Acessing the url directly "testname.app.invoicexpress.com/invoices.json?api_key=..."; the error dont appear, it appears "{ "invoices": [], "pagination": { "per_page": 10, "current_page": 1, "total_entries": 0, "total_pages": 0 } }".
Make a post request to an API error
I want to make a post request to an API to create a new client but its appearing an error:
Client error: `POST https://testname.app.invoicexpress.com/document-type.json?api_key=...`
resulted in a `404 Not Found` response: <!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en">
<![endif]--> <!--[if IE 7]> <html class="n (truncated...)
In the documentation "https://developers.invoicexpress.com/docs/versions/2.0.0/resources/invoices" says that to create a new client along with the invoice the curl command is like:
curl --request POST \
--url 'https://account_name.app.invoicexpress.com/:document-type.json?api_key=YOUR%20API%20KEY%20HERE' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{"invoice":{"date":"03/12/2017","due_date":"03/12/2017","client":{"name":"Client Name","code":"A1"},"items":[{"name":"Item Name","description":"Item Description","unit_price":"100","quantity":"5"}]}}'
But with the code below instead of the curl command, it shows that error.
public function generateInvoice()
{
$client = new \GuzzleHttp\Client();
$array = ['invoice' => [
'date' => date('Y-m-d H:i:s'),
'due_date' => date('Y-m-d H:i:s'),
'client' => ['name' => 'John', 'code' => ''],
'items' => [
'item' => [
'name' => 'item1',
'description' => 'item1 desc',
'unit_price' => '10',
'quantity' => '1.0'
],
'item' => [
'name' => 'item2',
'description' => 'item 2 desc',
'unit_price' => '10',
'quantity' => '1.0'
]
]
]];
$response = $client->request('POST', 'https://testname.app.invoicexpress.com/invoices.json', [
'query' => ['api_key' => '...'], 'form_params' => [$array],
]);
dd($response->getStatusCode());
}
Acessing the url directly "testname.app.invoicexpress.com/invoices.json?api_key=..."; the error dont appear, it appears "{ "invoices": [], "pagination": { "per_page": 10, "current_page": 1, "total_entries": 0, "total_pages": 0 } }".
I'm not sure what's missing or what makes it invalid. Maybe it's picky on how the formdata is being sent. Try replacing form_params with json and see if that changes anything. Maybe someone else will chip in and help out.
Please or to participate in this conversation.