API 403 Invalid token

Hi,
I setup the API in my account and I had my token key.

I tried in my project with the API → 403 Invalid token
Tried with a simple nodeJS project → 403 Invalid token
Tried on the https://api-docs.invoicing.co/ with my token → 403 Invalid token

Here is my nodeJS project

const axios = require(“axios”)

async function loadUrlGet(url) {
try {
const response = await axios({
url: ${url},
method: ‘get’,
headers: {
“X-API-Token”: “my64CharactersToken”,
“X-Requested-With”: “XMLHttpRequest”,
},
});
return response.data;
} catch (error) {
console.error(“Error fetching data:”, error.response ? error.response.data : error.message);
throw error;
}
}

async function executed() {

const clientExist = await loadUrlGet(https://app.invoiceninja.com/api/v1/clients?email=test);
}

executed()

Hi,

You’re using the v4 API URL, for v5 it should be invoicing.co.

Thanks, works now !
But the response is

Invoice Ninja
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
  name="description"
  content="Leading free invoice generator for freelancers and small businesses. Invoice clients, accept payments, track expenses &amp; time billable-tasks online."
/>...............

Only HTML, no JSON

Any idea ?

It may help to add "Content-Type": "application/json; charset=utf-8", to the headers.

My bad, I forget to say that I tested with and without, and that’s the same

I suggest trying to make it work using cURL and then comparing to your script.

Pffff, I was doing it on app .invoicing .co/api and not on invoicing .co/api xD

1 Like