Error while posting expense: Category can't be blank


#1

Hi there,

I’m having trouble creating an expense via API. Getting an error when
running this httpie request:

http POST "https://api.freeagent.com/v2/expenses" "Authorization:
Bearer $access_token" user="https://api.freeagent.com/v2/users/11111"
 dated_on="2019-01-24" description="Test" gross_value="10.00"
category="https://api.freeagent.com/v2/categories/285"

HTTP/1.1 422 Unprocessable Entity
{
“errors”: [
{
“message”: “category can’t be blank”
}
]
}

I’ve also tried as specified by the documentation to send a root
object expense, but whe I do that I get a different error:

http --form POST "https://api.freeagent.com/v2/expenses"
"Authorization: Bearer $access_token"
{"expense":    {"user":"https://api.freeagent.com/v2/users/11111","category":"https://api.freeagent.com/v2/categories/365",gross_value="10.00","dated_on":"2019-01-24","description":"Test"}}

HTTP/1.1 400 Bad Request
{
“errors”: {
“error”: {
“message”: “Expense or expenses data required”
}
}
}

Any help would be appreciated!


#2

Your data structure looks correct; it works for me with curl:

curl https://api.sandbox.freeagent.com/v2/expenses \
  -H "Authorization: Bearer $token" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{"expense":{"user":"https://api.sandbox.freeagent.com/v2/users/1234', "category":"https://api.sandbox.freeagent.com/v2/categories/280", "description":"test", "gross_value":"12.34", "dated_on":"2019-01-30"}}'

So I think you need to read the docs for httpie a bit more :wink:

Yours,
Andrew


https://doubleagent.io


#3

I think the Accept and Content-type could be the parameters I need! I’m gonna try soon. Thank you!