Add recurring invoices

Hello, I’m new to InvoiceNinja and I want to know how to create recurring invoices with the api.
Would be nice if someone could help me with that.

Hi,

Are you using v4 or v5?

Im currently using the v4

Thanks! In that case you can POST to /invoices and set is_recurring to true

Thanks for your help! It works. :grinning:

1 Like

I got one more question for adding recurring invoices.

I’m trying to create a recurring invoice via curl using this code:

$data = array(
		"client_id" => "1",
		"is_recurring" => true,
		"invoice_items" => array(
			"product_key" => "ITEM",
			"notes" => "Test",
			"cost" => 10,
			"qty" => 1
		)
	);

	$payload = json_encode($data);
	$type = 'POST';
	$token = 'mytoken'; 
	$curl = curl_init();
	$opts = [
		CURLOPT_URL => 'url',
		CURLOPT_RETURNTRANSFER => TRUE,
		CURLOPT_CUSTOMREQUEST => $type,
		CURLOPT_POST => $type === 'POST' ? 1 : 0,
		CURLOPT_POSTFIELDS => $payload,
		CURLOPT_HTTPHEADER  => [
			'Content-Type: application/json',
			'X-Ninja-Token: '. $token,
		],
	];
	curl_setopt_array($curl, $opts);
	$response = curl_exec($curl);
	curl_close($curl);
	echo $response;
	return $response;

As response I get this:

{“client_id”:“1”,“is_recurring”:true,“invoice_items”:{“product_key”:“ITEM”,“notes”:“Test”,“cost”:10,“qty”:1}}

However, no recurring invoice is created with the code.
I hope you can help me :laughing:

Edit: It looks like it is due to invoice_items. If I remove it, it works.
But somehow I have to specify my product from InvoiceNinja. Is only the product name required? Since I have entered my product name but it does not work.