API Invoice creation redirect error

First let me start by saying I love this software and the fact that I could restore a backup to a cloud system is just fantastic.

I have been working on a shell script for invoice creations from my google drive into Invoice Ninja (v4.4.4 | White label) and when I attempt to create the new invoice with the API as documented I am receiving an error message, see below, any help on what I am doing wrong would be greatly appreciated. Also I learned from my previous mistake and made the call from the command line as well as from the shell script and the same error returns. Also I re-used code already discussed in another post so I know the syntax is correct.

I stared out the personal data but I confirmed that the data is correct with no additional spaces or special characters in it.

---- ERROR ----
[root@linux ~]# curl --insecure -X POST -H Content-Type:application/json -H ‘X-Requested-With: XMLHttpRequest’ -d ‘{ “client_id”:“101”, “invoice_items”:[{“product_key”: “98941”, “notes”:"*** CREATED VIA AUTOMATION ***", “cost”:60, “qty”:1 }]}’ -H ‘X-Ninja-Token: *****************************qy’ https://192.168.2.250/api/v1/invoices
<!DOCTYPE html>
<html>
<head>
<meta charset=“UTF-8” />
<meta http-equiv=“refresh” content=“0;url=https://192.168.2.250” />

    &lt;title&gt;Redirecting to https://192.168.2.250&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    Redirecting to <a href="https://192.168.2.250">https://192.168.2.250</a>.
&lt;/body&gt;

---- Call Made —
curl --insecure -X POST -H Content-Type:application/json -H ‘X-Requested-With: XMLHttpRequest’ -d ‘{
“client_id”:“101”,
“invoice_items”:[{
“product_key”: “98941”,
“notes”:"*** CREATED VIA AUTOMATION ***",
“cost”:60,
“qty”:1
}
]}’ -H ‘X-Ninja-Token: *****************************qy’ https://192.168.2.250/api/v1/invoices

The redirect could mean the client id isn’t found.

Are you able to create a client through the API?

I am able to create a client through the API and the client ID maps to an active contact which I confirmed.

Odd thing is that I get data when I do the same thing without the ID_number=101 but all I get is this with the id value in the call.

[root@linux ~]# curl --insecure -X GET https://192.168.2.250/api/v1/clients?id_number=101 -H “X-Ninja-Token: ******************************3qy”
{
“data”: [],
“meta”: {
“pagination”: {
“total”: 0,
“count”: 0,
“per_page”: 15,
“current_page”: 1,
“total_pages”: 0,
“links”: []
}
}

Keep in mind ‘id’ and ‘id_number’ are different fields.

if the id is 101 you’d need to use: https://192.168.2.250/api/v1/clients/101

Ahh that I didn’t realized, I’ll look at this today/tomorrow and get back to you. Thanks for the help, it’s over and above what I expected out of the platform.

So I checked the DB to confirm and you are correct the account I was looking for was id=100 and client_id=101 but I tried the 100 and 101 id’s on both of the URL’s for the API call and this is what I get.

*************************** 1. row ***************************
id: 100
account_id: 1
user_id: 1
client_id: 101
created_at: 2018-07-26 12:14:14
updated_at: 2018-07-26 12:14:14

root@linux ~]# curl --insecure -X GET https://192.168.2.250/api/v1/clients/100 -H “X-Ninja-Token: ******************************3qy”
<!DOCTYPE html>
<html>
<head>
<meta charset=“UTF-8” />
<meta http-equiv=“refresh” content=“0;url=https://192.168.2.250” />

    &lt;title&gt;Redirecting to https://192.168.2.250&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    Redirecting to <a href="https://192.168.2.250">https://192.168.2.250</a>.
&lt;/body&gt;

</html>[root@linux ~]# curl --insecure -X GET https://192.168.2.250/api/v1/clients?id_number=100 -H “X-Ninja-Token: ******************************3qy”
{
“data”: [],
“meta”: {
“pagination”: {
“total”: 0,
“count”: 0,
“per_page”: 15,
“current_page”: 1,
“total_pages”: 0,
“links”: []
}
}

Only the id can be used as /api/clients/ for the id_number field you’d need to use /api/v1/clients?id_number=

https://invoice-ninja.readthedocs.io/en/latest/api.html#reading-data