Jump to content

Add a invoice for a server API


lolgc1

Recommended Posts

Hi.

 

I tried to add a invoice for a service but no success. Ive tried for like 1 hour now and cant get a solution.

 

$client_id = 15;

$service_id = 181;

$today = date("Y-m-d");

$response = $api->get("invoices", "add", array('vars' => array('client_id' => $client_id, 'date_billed' => $today, 'date_due' => $today, 'date_closed' => $today, 'date_autodebit' => $today, 'status' => 'active', 'currency' => '208', 'note_public' => 'Public note', 'note_private' => 'Privat note', array($service_id,'Desc', 1,1,0), 'period' => 'month', 'duration' => 'indefinitely', 'duration_time' => '1', 'recur_date_billed' => $today, 1)));

 

Does anyone know why it doesnt work? :)

Link to comment
Share on other sites

On 8/4/2018 at 5:26 AM, lolgc1 said:

Hi.

 

I tried to add a invoice for a service but no success. Ive tried for like 1 hour now and cant get a solution.

 

$client_id = 15;

$service_id = 181;

$today = date("Y-m-d");

$response = $api->get("invoices", "add", array('vars' => array('client_id' => $client_id, 'date_billed' => $today, 'date_due' => $today, 'date_closed' => $today, 'date_autodebit' => $today, 'status' => 'active', 'currency' => '208', 'note_public' => 'Public note', 'note_private' => 'Privat note', array($service_id,'Desc', 1,1,0), 'period' => 'month', 'duration' => 'indefinitely', 'duration_time' => '1', 'recur_date_billed' => $today, 1)));

 

Does anyone know why it doesnt work? :)

When the API doesn't work the way you expect, you should look at the errors you enconter, e.g.:

print_r($response->errors());

See the docs for an example.

From looking at your request, you are making a couple mistakes:

  1. You're using the "GET" HTTP verb to add something. "GET" [i.e. $api->get(..)] should only be used for retrieving information, not setting information. Use "POST" [i.e. $api->post(...)]
  2. You're not passing valid key => value pairs for all values expected by Invoices::add
    1. You have "array($service_id,'Desc', 1,1,0)". Is that supposed to be the line items? Why aren't they in key => value format?
    2. You have "...'recur_date_billed' => $today, 1)));". What is that extraneous 1 at the end of the list that is not in key => value format?

It'll be easier to figure out and avoid issues if you format your source code better:

$response = $api->get(
	"invoices", 
	"add",
	array(
		'vars' => array(
			'client_id' => $client_id, 
			'date_billed' => $today, 
			'date_due' => $today, 
			'date_closed' => $today, 
			'date_autodebit' => $today, 
			'status' => 'active', 
			'currency' => '208', 
			'note_public' => 'Public note', 
			'note_private' => 'Privat note', 
			array($service_id,'Desc', 1,1,0), 
			'period' => 'month', 
			'duration' => 'indefinitely', 
			'duration_time' => '1', 
			'recur_date_billed' => $today, 
			1
		)
	)
);

 

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...