Return result array

Hi guys,

I have the following array result:

Array
(
[result] => 1000
[resData] => Array
(
[domain] => mycooldomain.com
[status] => Active
[autorenew] => 0
[contactid] => 822
[nameserver1] => ns1.nameserver1
[nameserver2] => ns2.nameserver2
[nameserver3] => ns3.nameserver3
[nameserver4] => ns4.nameserver4
[nameserver5] =>
[registrationdate] => 2018-06-29
[expirydate] => 2020-11-03
)

)

I need to return the above nameservers in a return result:

    return array(
        'ns1' => $api->getFromResponse('nameserver1'),
        'ns2' => $api->getFromResponse('nameserver2'),
        'ns3' => $api->getFromResponse('nameserver3'),
        'ns4' => $api->getFromResponse('nameserver4'),
        'ns5' => $api->getFromResponse('nameserver5'),
    );

But I cannot get this returned,

I can return:

$api->getFromResponse(‘result’),

But nothing in the resData array.

Please advise?

What is the “full” code? As in, what are you doing to parse that array? Or rather, what are you doing on the server side to get the results to return.

I don’t know which way this is going, so clarity there will help.

Sure, apologies, so we have this function:

function _GetNameservers($params)

{
// user defined configuration values
$userIdentifier = $params[‘API Username’];
$apiKey = $params[‘API Key’];

// domain parameters
$sld = $params['sld'];
$tld = $params['tld'];
$registrationPeriod = $params['regperiod'];

// Build post data
$postfields = array(
    'username' => $userIdentifier,
    'password' => $apiKey,
    'testmode' => $testMode,
    'domain' => $sld . '.' . $tld,
);

try {
    $api = new ApiClient();
    $api->call('GetNameservers', $postfields);

    return array(
        'success' => true,
        'ns1' => $api->getFromResponse('nameserver1'),
        'ns2' => $api->getFromResponse('nameserver2'),
        'ns3' => $api->getFromResponse('nameserver3'),
        'ns4' => $api->getFromResponse('nameserver4'),
        'ns5' => $api->getFromResponse('nameserver5'),
    );

} catch (\Exception $e) {
    return array(
        'error' => $e->getMessage(),
    );
}

}

When the API call above is done, the server returns:

Array

(
[result] => 1000
[resData] => Array
(
[domain] => mycooldomain.com
[status] => Active
[autorenew] => 0
[contactid] => 822
[nameserver1] => ns1.nameserver1
[nameserver2] => ns2.nameserver2
[nameserver3] => ns3.nameserver3
[nameserver4] => ns4.nameserver4
[nameserver5] =>
[registrationdate] => 2018-06-29
[expirydate] => 2020-11-03
)

)

I need to return ns1-ns4 in the function:

        'ns1' => $api->getFromResponse('nameserver1'),    

But I cannot for the life of me get this to work, I’ve tried:

        'ns1' => $api->getFromResponse('resData.nameserver1'),
        'ns1' => $api->getFromResponse([resData][nameserver1]),

So, I see you making the call, I assume, with

$api->call()
Shouldn’t you be capturing what it returns? Something like,

$resp = $api->call();
Then, you can see what is returned by doing, (for testing)
print_r($resp);

Sponsor our Newsletter | Privacy Policy | Terms of Service