When manually using curl from the cli, the new client is created with the submitted data:
curl -X POST "https://selfhosted.ninja/api/v1/clients" -H "Content-Type:application/json" -H "X-Ninja-Token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -d '{"name":"Client","contact":{"email":"test@example.com","first_name":"Claudio","last_name":"Kuenzler"}}'
But when I try to use the same using PHP curl
, a new client is created but without the data:
$payload = "{'name' : 'Fixed Company'}";
$curl = curl_init();
$opts = [
CURLOPT_URL => 'https://selfhosted.ninja/api/v1/clients',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-Ninja-Token: '. $token,
],
CURLOPT_POSTFIELDS => [ $payload ],
];
curl_setopt_array($curl, $opts);
$response = curl_exec($curl);
$info = curl_getinfo($curl);
curl_error($curl);
curl_close($curl);
The request is successfully sent to Invoiceninja, a new client is created, but the name is empty instead of “Fixed Company”. I was also looking into possible problems with the data and used json_encode($payload)
but this didn’t help either. Any idea?