1

I'm now working with Name.com API, They have documentary explanation of how to get details.

I've made everything right, But, I can't print the result.

I've done var_dump() to debug and here is the result:

object(stdClass)#4 (2) { 
    ["result"]=> object(stdClass)#5 (2) { 
        ["code"]=> int(100) ["message"]=> string(18) "Command Successful" 
    } 
    ["domains"]=> object(stdClass)#6 (8) { 
        ["mynewdomain.mobi"]=> object(stdClass)#7 (5) { 
            ["avail"]=> bool(true) 
            ["tld"]=> string(4) "mobi" 
            ["price"]=> string(4) "8.99" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(false) 
        } 
        ["mynewdomain.net"]=> object(stdClass)#8 (5) { 
            ["avail"]=> bool(false) 
            ["tld"]=> string(3) "net" 
            ["price"]=> string(5) "49.95"
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(true) 
        } 
        ["mynewdomain.org"]=> object(stdClass)#9 (5) { 
            ["avail"]=> bool(true) 
            ["tld"]=> string(3) "org" 
            ["price"]=> string(4) "9.99" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(false) 
        } 
        ["mynewdomain.info"]=> object(stdClass)#10 (5) { 
            ["avail"]=> bool(true) 
            ["tld"]=> string(4) "info" 
            ["price"]=> string(4) "3.99" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(false) 
        } 
        ["mynewdomain.com"]=> object(stdClass)#11 (5) { 
            ["avail"]=> bool(false) 
            ["tld"]=> string(3) "com" 
            ["price"]=> string(5) "49.95" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(true) 
        } 
        ["mynewdomain.biz"]=> object(stdClass)#12 (5) { 
            ["avail"]=> bool(false) 
            ["tld"]=> string(3) "biz" 
            ["price"]=> string(5) "29.95" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(true) 
        } 
        ["mynewdomain.me"]=> object(stdClass)#13 (5) { 
            ["avail"]=> bool(false) 
            ["tld"]=> string(2) "me" 
            ["price"]=> string(5) "49.95" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(true) 
        } 
        ["mynewdomain.tv"]=> object(stdClass)#14 (5) { 
            ["avail"]=> bool(false) 
            ["tld"]=> string(2) "tv" 
            ["price"]=> string(5) "49.95" 
            ["premium"]=> bool(false) 
            ["backorder"]=> bool(true) 
        }
    } 
}

and this is another short result for listing domains:

object(stdClass)#4 (2) { 
    ["result"]=> object(stdClass)#5 (2) { 
        ["code"]=> int(100) 
        ["message"]=> string(18) "Command Successful" 
    } 
    ["domains"]=> array(0) { } 
}

I tried the following:

  • echo $response

  • echo $response->domains

  • echo $response['domains']

But really, I can't get it to work..Could someone help me with that ?

Thanks in advance,

3 Answers 3

3

Try this one to get message:

echo $response->result->message;

To get domain list:

foreach ($response->domains as $domainName => $domainData)
{

    echo $domainName.": available-".$domainData->avail."; price - ".$domainData->price;

}
Sign up to request clarification or add additional context in comments.

5 Comments

I get the message successfully but the list gives me white page.
@MohamedMagdy did you try my code below? $domainData is the StdClass object
Tried it again with check_domain as I was trying it for list_domains, Message came successfully but all domains are available, It's not checking.
@MohamedMagdy in your second example domains is empty array. i posted code for first example where domains is stdClass object. may be you check it out with second data?
I've tried your code for this $response = $api->check_domain('example'); It worked successfully with the listing and price but all is availabe, Do you want to me to send you the full API with all classes inside ?
1

Looks like you are getting a bunch of Objects back so you need to iterate through $response->domains. I'd push that to a new var for easier handling like:

$domains = &$response->domains;

foreach($domains as $key => $value) {
  echo $key.":\n";
  foreach($value as $a => $b) {
    if($b === true) $b = 'yes';
    if($b === false) $b = 'no';
    echo $a.": ".$b."\n";
  }
}

Note: $response->result ONLY contains the result of the command you sent the server. Check that to make sure you didnt error but dont expect your data to be in there.

14 Comments

I've tried this and get a white page, by debugging, I get: array(0) { }
Can you please do a serialize($response); - echo it and post it so I can bring the class into a test page and see whats going on?
Result has been came up but all domains are available: example.orgstdClass Object ( [avail] => [tld] => org [price] => 49.95 [premium] => [backorder] => 1 ) example.netstdClass Object ( [avail] => [tld] => net [price] => 49.95 [premium] => [backorder] => 1 ) example.infostdClass Object ( [avail] => [tld] => info [price] => 49.95 [premium] => [backorder] => 1 ) example.mobistdClass Object ( [avail] => [tld] => mobi [price] => 49.95 [premium] => [backorder] => 1 )
OK so looks like it works then, I'll edit my answer to handle the objects in domain.
Thank you, I've tried your edited code and got all the objects but the same problem before, All domains are available, That's the result: google.com: avail: tld: com price: 9.99 premium: backorder: Here it's also the serialize:O:8:"stdClass":2:{s:6:"result";O:8:"stdClass":2:{s:4:"code";i:100;s:7:"message";s:18:"Command Successful";}s:7:"domains";O:8:"stdClass":8:{s:10:"google.net";O:8:"stdClass":5:{s:5:"avail";b:0;s:3:"tld";s:3:"net";s:5:"price";s:5:"49.95";s:7:"premium";b:0;s:9:"backorder";b:1;}}}
|
0

It seems to me that everything is in a result array first. Try this:

echo $response["result"]["domains"];

3 Comments

domains isn't a child element of result
Not worked: Fatal error: Cannot use object of type stdClass as array
Hmmm, sorry, I didn't notice when the output was on one line when I answered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.