how to use dreamscape api in nodejs for check domain name

Viewed 161

I have already work this in php. Here is my working code:

$request = array(
        'DomainNames' => $domain_names
    );
$response = dreamScapeAPI('DomainCheck', $request);

$available = false;
    $alt_domains = array(); // Alternative to user's expected domain names

    if (!is_soap_fault($response)) {
        // Successfully checked the availability of the domains
        if (isset($response->APIResponse->AvailabilityList)) {
            $availabilityList = $response->APIResponse->AvailabilityList;
            foreach ($availabilityList as $list) {
                if ($list->Available){
                    if ($domain == $list->Item) {
                        $available = true; // user prefered domain found
                    }
                    else {
                        $alt_domains[] = $list->Item;
                    }
                }
            }
        } 
    else {
           $error = $response->APIResponse->Errors;
           foreach ($error as $e) {
               $api_error = $e->Message;
               //echo $e->Item . ' - ' . $e->Message . '<br />';
           }
        }
    } 


function dreamScapeAPI($method, $data = null) {
    $reseller_api_soap_client = "";

    $soap_location = 'http://soap.secureapi.com.au/API-2.1';
    $wsdl_location = 'http://soap.secureapi.com.au/wsdl/API-2.1.wsdl';
    
    $authenticate = array();
    $authenticate['AuthenticateRequest'] = array();
    $authenticate['AuthenticateRequest']['ResellerID'] = '**';
    $authenticate['AuthenticateRequest']['APIKey'] = '**';

    //convert $authenticate to a soap variable
    $authenticate['AuthenticateRequest'] = new SoapVar($authenticate['AuthenticateRequest'], SOAP_ENC_OBJECT);
    $authenticate = new SoapVar($authenticate, SOAP_ENC_OBJECT);

    $header = new SoapHeader($soap_location, 'Authenticate', $authenticate, false);

    $reseller_api_soap_client = new SoapClient($wsdl_location, array('soap_version' => SOAP_1_2, 'cache_wsdl' => WSDL_CACHE_NONE));
    $reseller_api_soap_client->__setSoapHeaders(array($header));


    $prepared_data = $data != null ? array($data) : array();

    try {
        $response = $reseller_api_soap_client->__soapCall($method, $prepared_data);
    } catch (SoapFault $response) { }

    return $response;


}

I tried with this : https://github.com/dan-power/node-dreamscape

But domain search can not work properly. Mainly, I want it on nodejs using nodejs dreamscape api but this method is not available on nodejs.

Here is my working demo: click here

0 Answers
Related