Getting 404 on creating an invoice

Hi,

I’m getting persistent 404s when trying to create an invoice - other API requests are succeeding, and I’m authorised. Here is the request details of the failing request. What am I doing wrong?

Server responded with 404 on query 
https://api.freeagent.com/v2/invoices 
{
	"errors":
	{
		"error":
		{
			"message":"Resource not found"
		}
	}
} 

- request content was:
{
	"invoice":
	{
		"status":"Draft",
		"contact":"https://api.freeagent.com/v2/contacts/954057",
		"dated_on":"2018-10-08",
		"payment_terms_in_days":0,
		"comments":"ec2342e0-95ec-4d57-920e-6f45ae64bdd9",
		"total_value":0.0,
		"paid_value":0.0,
		"due_value":27.0,
		"discount_percent":0.0,
		"invoice_items":
		[{
			"id":0,
			"position":1.0,
			"item_type":"Services",
			"quantity":1.0,
			"description":"Recharged Services by (Redacted)",
			"price":24.0,
			"sales_tax_rate":0.0,
			"category":"https://api.freeagent.com/v2/categories/731",
			"_destroy":0
		},
		{
			"id":0,
			"position":2.0,
			"item_type":"Services",
			"quantity":1.0,
			"description":"Service Fee",
			"price":3.0,
			"sales_tax_rate":0.0,
			"category":"https://api.freeagent.com/v2/categories/001",
			"_destroy":0
		}],
		"created_at":"2018-10-08T00:00:00Z"
	}
}

Hi Adam,

Ewa here from the Engineering Team at FreeAgent — I’m sorry to hear you’ve had some trouble and I’ll do my best to help out.

This type of error usually occurs if one of the resources referenced in the body of your request cannot be found in the FreeAgent account you’re authenticated against. My initial guess would be that the contact id at the end of the following line might be missing a digit:

"contact":"https://api.freeagent.com/v2/contacts/954057"

Could you please check if that might be the case and let me know if the problem persists?

Best wishes,

Ewa

Hi Ewa,

Sorry, the correct contact got deleted in my formatting of the json, accidentally, the actual JSON had an extra 0 at the end, which was correct. Still getting 404 posting to create the invoice, but when I try getting the contact, it works fine.

Also, the referenced category appears to exist when requested, and the invoice endpoint works with a get request to return a list of the zero invoices I’ve so far managed to add.

Hi Adam,

Ah, it couldn’t be that easy, could it :smiley:Taking a closer look at you request body, I can see you’re passing "id":0 for each invoice item you’re trying to create. Invoice item id is a valid attribute when you’re updating or deleting an existing invoice item, but not when you’re creating a new one. You can see what a sample POST request to create an invoice could look like in our documentation here.

Best wishes,

Ewa

HI Ewa,

That’s fixed it. Thanks.