Getting stuck at post to a Rest API with multiple arguments. I'm trying to change nameservers with an API.
The error i get: "ObjectInvalid|Nameserver object invalid. Minimum of 2 nameservers is required.".
I understand the "ns" part is wrong. In the guide i only find this: "ns" : [{ns="ns1.domain.com", nsip=""},{ns="ns2.domain.com", nsip=""}],
This is my code:
$values = array(
"domain" => "mydomain.com",
"ns" => "[{ns='ns1.domain.com', nsip=''},{ns='ns2.domain.com', nsip=''}]",
"contact_id" => 123456,
"years" => 1
);
// Set POST to 1 and send the array with values as a JSON-string
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_URL => "https://www.apiurl.com/api/v1/domains/$domain/update",
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_USERPWD => "username:password"
));
ns-string as a PHP array instead? You're already runningjson_encode()of the complete payload anyway."ns" => "[{ns='ns1.domain.com', nsip=''},{ns='ns2.domain.com', nsip=''}]". Since you run it throughjson_encode($values)later, that gets double encoded and then most likely cannot be understood by the API. Make it a normal PHP subarray and letjson_encodedo the job.