I want to make a post request to this API "https://invoicexpress.com/api/invoices/create" to create a new client.
In that documentatio page says that the required fields are: date, due_date, client and items.
I have the code below but Im getting an error:
Client error: POST https://nametest.app.invoicexpress.com/invoices.xml?api_key=...
resulted in a `422 Unprocessable Entity` response:
<?xml version="1.0" encoding="UTF-8"?> <errors> <error>
Expected <invoice></error> </errors>
Do you know why that error is appaering?
Code:
public function createClient(){
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://nametest.app.invoicexpress.com/invoices.xml', [
'query' => ['api_key' => '...'],
'date' => date('Y-m-d H:i:s'),
'due_date' => date('Y-m-d H:i:s'),
'client' => 'John',
'code' => '',
'items' => [
'item' => [
'name' => 'item1',
'description' => 'item1 desc',
'unit_price' => '10',
'quantity' => '1'
],
'item' => [
'name' => 'item2',
'description' => 'item2 des',
'unit_price' => '10',
'quantity' => '1'
]
]
]);
dd($response->getStatusCode());
}