422 unprocessable entry when creating new contact

I’ve been working on an integration between Taxi For Email and Freeagent.
We’re trying to generate invoices for automated credit card transactions
from our web app. I’m having trouble creating new contacts through the
API. I tried using httpbin (as recommended in your trouble shooting
guide). Here’s the post request that I made - as seen in httpbin:

{
“args”: {},
“data”: “{“organisation_name”:“API Test
Org",“first_name”:“Aypee”,“last_name”:“eye”,“email”:"email@email.com”}”,
“files”: {},
“form”: {},
“headers”: {
“Accept”: “application/json”,
“Accept-Encoding”: “gzip, deflate”,
“Authorization”: “Bearer [Sanitised]”,
“Content-Length”: “101”,
“Content-Type”: “application/json”,
“Host”: “httpbin.org”,
“User-Agent”: “Ruby”
},
“json”: {
“email”: "email@email.com",
“first_name”: “Aypee”,
“last_name”: “eye”,
“organisation_name”: “API Test Org”
},
“origin”: “80.87.18.226”,
“url”: “http://httpbin.org/post
}

And here is the response from the same request through the Freeagent API:

{“errors”:[{“message”:“first_name can’t be blank”},{“message”:“last_name
can’t be blank”},{“message”:“organisation_name can’t be blank”}]}

Approximate timestamp: Thu, 07 Jan 2016 17:56:31 +0000

I’ve run out of things to try here, any help much appreciated

Thanks

W

Hey Will,

The API expects the contact data to be wrapped in a root “contact” element, as you can see in the example response in the docs at FreeAgent Developer Dashboard

If you just nest your JSON so it looks like the following, it should work fine for you:

{
“contact”: {
“first_name”: “Caius”,
“last_name”: “Durling”,
“email”: “caius@freeagent.test”
}
}

Hope that helps, and please come back if that doesn’t solve your issue.

Thanks,
C
Caius Durling
Engineer, FreeAgent

One Edinburgh Quay, 133 Fountainbridge, Edinburgh, EH3 9QG
FreeAgent Central Ltd. Registered in sunny Scotland SC316774