Reputation: 21
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"
));
Upvotes: 2
Views: 71
Reputation: 4534
It's hard to tell exactly without seeing the documentation, but most probably you should leave the serialization of the nameservers to json_encode
too:
$values = array(
"domain" => "mydomain.com",
"ns" => [
[
"ns" => "ns1.domain.com",
"nsip" => ""
],
[
"ns" => "ns2.domain.com",
"nsip" => ""
],
],
"contact_id" => 123456,
"years" => 1
);
Upvotes: 4