API installation on selfhost

Hi Invoice Ninja!

I have a quick question… I want to install the PHP API onto my selfhost installation on Invoice Ninja. On GitHub I see the following line in the setup:
NinjaConfig::setURL(‘https://ninja.dev/api/v1’);

What url do I have to put there? Is replacing ninja.dev with my own domain (where I installed Invoice Ninja) good enough?

Also, is there a detailed documentation about the API?

I hope to hear something!

My sincerely,

Nick van Kesteren

Just to clarify… I think you’re referring to our PHP SDK.

To use the SDK you need to include the SDK code in your project and then replace the URL.

The SDK documentation is in the GitHub readme, you can see our API documentation here:

http://docs.invoiceninja.com/en/latest/api.html
https://app.invoiceninja.com/api-docs#/

Yes I was talking about the PHP SDK. Which URL do I need to put there?

I’ve tested the URL of my Invoice Ninja installation with the following cURL request: curl -X GET ninja.test/api/v1/clients -H “X-Ninja-Token: TOKEN”
The TOKEN I filled in was an API token created in my Invoice Ninja installation. I’ve tried multiple URL’s but none worked. Just replacing ‘ninja.test’ with my domain (and then adding /api/v1/clients) results in a 400 bad request error.

I’m sorry if I’m not so clear haha, not a native English speaker :slight_smile:

I think you need to remove ‘/clients’ from the URL

The code from my previous message was to get clients via cURL. That code was precisely the code that was in the API documentation. I’ve tested that code on http://onlinecurl.com/. I’ve only changed the token and the url. The only thing I get is a http 400 bad request error.

This is my cURL code (without valid token): curl -X GET congreatspay.eu/api/v1/clients -H “X-Ninja-Token: VALIDTOKEN”

/clients needs to be there for the right command right. I think /api/v1 doesn’t work on my self hosted version or something. Or that part of the url needs to be something else. If you want to test it I could send a test key via email.

Am I doing something wrong? Hopefully you can help me.

To load clients with the API you’d use domain.com/api/v1/clients

To load clients (or any other records) with the SDK you’d use domain.com/api/v1, the SDK add ‘/clients’

I’ve just tested the command from my previous message on my Macbook. There I get a 404 error. /api/v1 is nothing on my Invoice Ninja installation. Do I need to use something else? Because the link you said in the message above is precisely the link I use, I only changed ‘domain.com’ to my real domain.

Try echoing out the $url here to see what’s being used by the SDK

https://github.com/invoiceninja/sdk-php/blob/master/src/InvoiceNinja/Models/AbstractModel.php#L159

Wait… Do I have to install the SDK on the Invoice Ninja server? I thought the SDK was there to make a connection between a project and my Invoice Ninja server. I’ve not yet installed the PHP SDK into a project.

I first wanted to try the connection. So I just picked the first cURL API command from the API documentation, edited the data and ran the command. But until now that only results in a 400 and 404 error. Do I need to install something before I can use the API?

Hopefully you can help me.

You would need to add the SDK code to your project to use it.

I’d suggest checking your web server error logs for more info about the 4xx errors. You may need to add /public if you’ve left it in the app url.