Create invoice API fails.
I'm trying to create invoices through the API.
<?xml version="1.0" encoding="UTF-8"?>
<invoice>
<company-id>28843</company-id>
<project-id>18668</project-id>
<dated-on>2009-01-30T14:34:37Z</dated-on>
<reference>1</reference>
<status>Draft</status>
<payment-terms>14</payment-terms>
</invoice>
Array
(
[url] => https://marko.freeagentcentral.com/in...
[content_type] => application/xml; charset=utf-8
[http_code] => 400
[header_size] => 509
[request_size] => 526
[filetime] => -1
[ssl_verify_result] => 19
[redirect_count] => 0
[total_time] => 0.233
[namelookup_time] => 0
[connect_time] => 0.032
[pretransfer_time] => 0.153
[size_upload] => 0
[size_download] => 189
[speed_download] => 189
[speed_upload] => 0
[download_content_length] => 189
[upload_content_length] => 0
[starttransfer_time] => 0.233
[redirect_time] => 0
)
cURL error number:0 cURL error:
HTTP/1.1 400 Bad Request
Date: Fri, 11 Sep 2009 02:38:45 GMT
Server: Apache/2.2.3 (Red Hat) DAV/2 Phusion_Passenger/2.2.5 PHP/5.1.6 mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 mod_perl/2.0.4 Perl/v5.8.8
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.5
X-Runtime: 34
Cache-Control: no-cache
Set-Cookie: _session_id=fd6e9c00b1de249c2a890ce555e7d2f4; domain=.freeagentcentral.com; path=/; HttpOnly
Content-Length: 189
Status: 400
Connection: close
Content-Type: application/xml; charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Project is invalid</error>
<error>Payment terms in days is not a number</error>
<error>Contact can't be blank</error>
</errors>
At least this is better then before, when I tried to post a more complex xml. This resulted in no errors at all, but a 400 all the same.
<?xml version="1.0" encoding="UTF-8"?>
<invoice>
<company-id>28843</company-id>
<project-id>18668</project-id>
<dated-on>2009-01-30T14:34:37Z</dated-on>
<reference>1</reference>
<status>Draft</status>
<payment-terms>14</payment-terms>
</invoice>
Array
(
[url] => https://marko.freeagentcentral.com/in...
[content_type] => application/xml; charset=utf-8
[http_code] => 400
[header_size] => 509
[request_size] => 526
[filetime] => -1
[ssl_verify_result] => 19
[redirect_count] => 0
[total_time] => 0.233
[namelookup_time] => 0
[connect_time] => 0.032
[pretransfer_time] => 0.153
[size_upload] => 0
[size_download] => 189
[speed_download] => 189
[speed_upload] => 0
[download_content_length] => 189
[upload_content_length] => 0
[starttransfer_time] => 0.233
[redirect_time] => 0
)
cURL error number:0 cURL error:
HTTP/1.1 400 Bad Request
Date: Fri, 11 Sep 2009 02:38:45 GMT
Server: Apache/2.2.3 (Red Hat) DAV/2 Phusion_Passenger/2.2.5 PHP/5.1.6 mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 mod_perl/2.0.4 Perl/v5.8.8
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.5
X-Runtime: 34
Cache-Control: no-cache
Set-Cookie: _session_id=fd6e9c00b1de249c2a890ce555e7d2f4; domain=.freeagentcentral.com; path=/; HttpOnly
Content-Length: 189
Status: 400
Connection: close
Content-Type: application/xml; charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Project is invalid</error>
<error>Payment terms in days is not a number</error>
<error>Contact can't be blank</error>
</errors>
At least this is better then before, when I tried to post a more complex xml. This resulted in no errors at all, but a 400 all the same.
1
person has this problem
I have this problem, too!
Tell me when someone solves it.
The more people who report this problem, the more it gets noticed.
The more people who report this problem, the more it gets noticed.
The company marked this problem solved.
-
Inappropriate?Hi Marko
It looks like we had a typo in the API documentation, sorry about that -- I've now fixed it.
Instead of company-id you need to you contact-id. Please can you try this and let me know how you get on.
1 person says
this solves the problem
-
Inappropriate?Hey Olly,
Great service, I'm one step further. Now I get some errors posting items:
<?xml version="1.0" encoding="UTF-8"?>
<invoice-items>
<invoice-item>
<item-type>Services</item-type>
<description>Project Management</description>
<price>160.00</price>
<quantity>2.00</quantity>
<sales-tax-rate>19.0</sales-tax-rate>
</invoice-item>
</invoice-items>
Array
(
[url] => https://marko.freeagentcentral.com/in...
[content_type] => application/xml; charset=utf-8
[http_code] => 400
[header_size] => 509
[request_size] => 3374
[filetime] => -1
[ssl_verify_result] => 19
[redirect_count] => 0
[total_time] => 0.458
[namelookup_time] => 0
[connect_time] => 0.031
[pretransfer_time] => 0.152
[size_upload] => 0
[size_download] => 196
[speed_download] => 196
[speed_upload] => 0
[download_content_length] => 196
[upload_content_length] => 0
[starttransfer_time] => 0.458
[redirect_time] => 0
)
cURL error number:0 cURL error:
HTTP/1.1 400 Bad Request
Date: Fri, 11 Sep 2009 12:13:17 GMT
Server: Apache/2.2.3 (Red Hat) DAV/2 Phusion_Passenger/2.2.5 PHP/5.1.6 mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 mod_perl/2.0.4 Perl/v5.8.8
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.5
X-Runtime: 18
Cache-Control: no-cache
Set-Cookie: _session_id=6a161a2f31720e097183634102b302b1; domain=.freeagentcentral.com; path=/; HttpOnly
Content-Length: 196
Status: 400
Connection: close
Content-Type: application/xml; charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Description can't be blank</error>
<error>Item type can't be blank</error>
<error>Item type is not an accepted value</error>
</errors>
Any ideas?
I’m hoping....
-
Inappropriate?I notice you don't have invoice-id in the invoice item XML. Can you try adding that?
-
Inappropriate?<invoice-item>
<invoice-id>66087</invoice-id>
<project-id>18668</project-id>
<item-type>Services</item-type>
<description>Project Management</description>
<price>160.00</price>
<quantity>0.50</quantity>
<sales-tax-rate>19.0</sales-tax-rate>
</invoice-item>
<errors>
<error>Description can't be blank</error>
<error>Item type can't be blank</error>
<error>Item type is not an accepted value</error>
</errors>
No luck, but maybe I'm doing it wrong.
I’m silly
-
Inappropriate?Do I need to send a separate request for each item or can I add multiple items in one request?
I’m silly
-
Inappropriate?Hi Marko
Sorry you're having trouble.
You do need to send a separate request for each invoice item you want to create. You should also remove the invoice-items tags -- this may be part of the problem.
For clarity, the URL should be of the form:
youraccount.freeagentcentral.com/invoices/[id]/invoice_items
You should ensure this is a POST request and that the 'Accept' header is set to application/xml. Is this the case?
Please ignore my earlier comment about the invoice-id field, this isn't necessary since it's implied from the URL (my mistake).
Hopefully it will work for you now.
1 person says
this solves the problem
-
Inappropriate?One more thing:
I've imported my invoices fine. However, they are not properly totalled up and I have to go in and touch every one by hand. Can you help?
I’m happy
-
Inappropriate?This happens when I have multiple item-lines in an invoice, only the last item is calculated towards the total. If I go in the UI and change the status back to draft, it's calculated correctly...
-
Hi
We should actually be preventing you from adding invoice items to invoices which are not in Draft state -- this looks like an oversight in the API which we'll look at addressing. We cache totals on Sent invoices, hence the issue you're seeing.
Thanks for letting us know.
Loading Profile...



