Problem with customers and recurring invoices

Good evening, I have difficulties creating new customers and recurring invoices. If I want to create a customer using the API, the customer will be created in the clients table but the user_id and account_id will always remain at 1. Unfortunately, nothing will be created in the users table except when I create a customer manually.

The other problem I have is with the recurring invoices. According to the InvoiceNinja API, a client_id must be specified for recurring invoices but what exactly is the client_id?


The users table is for application users, do you mean the ‘contacts’ table?

After you create a client the id will be included in the response.

I mean clients that are created with the api in the table ‘clients’. The user_id and the account_id is always 1


The user/account id will be set to match the API token’s user/account id

My problem is that the user id always stays at 1 although I specify the user_id in the POST. The customerid has the value 27 but in the invoice client table the customer gets the id 1 which should not be the case.

$data = array(
	"user_id" => $user['customerid']

$payload = json_encode($data);
$type = 'POST';
$token = '...'; 
$curl = curl_init();
$opts = [
	CURLOPT_URL => '...',
	CURLOPT_POST => $type === 'POST' ? 1 : 0,
		'Content-Type: application/json',
		'X-Ninja-Token: '. $token,
curl_setopt_array($curl, $opts);
$response = curl_exec($curl);
$json = json_decode($response);

The user_id can not be specified, it will be copied from the token. If you want to assign the invoice to a different user you’d need to create it with the user’s token.

Note: in v5 the app supports assigning invoices to users by setting the assigned_user_id field.

I am currently trying to implement it so that a customer can order a product. I want to create a recurring invoice and therefore I have to specify the client_id at the api. But I don’t understand what you mean with the user_id and the token? Can you give me an example or something like that? That would be very nice.

I think you may be mixing up the client_id and the user_id fields.

I tried to add a client with the example from the documentation:

All clients always get the user_id and the account_id 1 (the one user that is in the users table) Am I confusing what or why is this so?

I’m not sure I understand, are you trying to assign the invoice to a different user?

So once again from the beginning :slight_smile:

We want to create a customer via the API and then, when he orders something, create a recurring invoice for this customer.
But if you create the customer via the API, he will get the user_Id “1” every time, no matter how many we create it is always the “1”. So we can’t create a recurring invoice correctly because all customers have the user_id “1”.

If we create a customer using the normal Invoice Ninja Dashboard, everything works perfectly, so every customer gets his own id

So how can we create a customer via the API that gets a preceding user_id so that we can assign a recurring invoice?

Thanks a lot

Again… I think the field you want to set is client_id.

If you only have one user in your account all clients will be linked to the same user.

Okay and then how do we create the recurring invoices? How can we say in the API that this should be assigned to a user? Do we need the normal “id”?

Even with this it’s not working:

$data = array(
“client_id” => “5”,
“name” => “Testname”

Are you trying to assign the invoice to a specific ‘user’ or ‘client’?

If you’re creating an invoice the ‘name’ field isn’t supported