Reputation: 481
I have this function that connects to an external API:
function ICUK_Request($url, $method = 'GET', $body = NULL) {
$client = new IcukApiClient();
$client->username = "user";
$client->key = "pass";
$client->encryption = "SHA-512";
$req = new IcukApiRequest();
$req->url = $url;
$req->method = $method;
if(!is_null($body)) {
$req->body = $body;
}
$res = $client->send($req);
if ($res->success) {
$obj = json_decode($res->response);
}
else {
throw new Exception('There was an error contacting the API.');
}
return $obj;
}
the API docs are telling me to send the POST request like this:
POST /domain/registration/new/
{
"domain_name": "domain.co.uk",
"hosting_type": "NONE",
"registration_length": 1,
"auto_renew": false,
"domain_lock": false,
"whois_privacy": false,
"contact_registrant_id": 1
}
so i tried this:
$arr = array(
"domain_name" => "domain.co.uk",
"hosting_type" => "NONE",
"registration_length" => 1,
"auto_renew" => false,
"domain_lock" => false,
"whois_privacy" => false,
"contact_registrant_id" => 1
);
ICUK_Request("/domain/registration/new", "POST", $arr);
but thats giving me a response in the API Logs saying:
{
"exception_message": "Internal API exception occured",
"exception_type": "InternalApiException"
}
im not sure if this would be anything generic and if anyone can help on how to POST the data?
Upvotes: 1
Views: 66
Reputation: 10757
Send it as json:
$values = json_encode($arr);
ICUK_Request("/domain/registration/new", "POST", $values);
Upvotes: 2