Sign in to participate

Be Kind, Be Helpful

Ask a question, answer a question, and get to know the fine people in the Harvest community.

Forum powered by Altered Beast
This is a Topic in API and Developers

JSON Support for Expenses API Endpoint

Avatar

I am working with JSON against the Harvest API and have user authentication, time entry operations, and expense category and expense retrieval working as desired. At this point I am attempting to get expense creation working appropriately but am having a few problems.

If I use the XML method (application/xml as Accept and Content-Type headers, POSTing XML like the sample http://www.getharvest.com/api/expense-tracking) everything works appropriately. However, if I post JSON containing the same information and with the appropriate headers, I get back a JSON error message as follows:

{
“error”: {
“kind”: “UserNotAssigned”,
“message”: “This expense is missing a project”
}
}

The following is the JSON I am posting:

{
“notes”: “Buy Valentine’s Day chocolates for Harvest”,
“total-cost”: 11.34,
“project_id”: 1504605,
“expense_category_id”: 701315,
“spent_at”: “Thu, 08 Sep 2011”
}

I am authenticating correctly given the fact that all other operations exist, but I just cannot get this to work yet. Interestingly, I get the same message when I post the XML without the expense_category_id field in the XML body but, as you can see, I am correctly specifying that field in the JSON.

Avatar

Just as a note to anyone who sees this, I got this confirmed as a bug by the Harvest developers and hopefully it’ll be fixed soon.

Avatar

Thanks for beating me to the punch on that Nick. Yes, if anyone else runs into this, just drop us a line at support@harvestapp.com.

Avatar

I am now getting a different error message (so I’m assuming there is some movement on this issue). As noted above, I was receiving the message:

{
  “error”: {
    “kind”: “UserNotAssigned”,
    “message”: “This expense is missing a project”
 }
}

Now, I am receiving the following message when attempting to use JSON to create an expense:

{
  "error": {
    "kind": "UserNotAssigned",
    "message": "Cannot create record as the User is not assigned to the requested project."
  }
}

This error message appears to be incorrect because the User I am specifying in my authentication string is certainly assigned to the project ID that I am posting. I know this because I made a request to /daily with the same authentication string and received the project ID in the response.

Again, any and all help would be appreciated :)

Avatar

Hi Nick,

Haven’t heard back an official “fixed” on this. Just wondering if you can send me a quick email at support at harvestapp.com with the details (user/project) so I can check into it specifically for you.

Jon

Avatar

Jon, sent you an email with as much detail as I could muster. Let me know if you need anything else and thanks so much!

Avatar

Thanks Nick!

Not completely resolved yet, but part of the problem (if anyone is searching through here for an answer) is that from Nick’s example, the JSON packet needs to have an expense wrapper. So:

"expense": {
	{
	“notes”: “Buy Valentine’s Day chocolates for Harvest”,
	“total-cost”: 11.34,
	“project_id”: 1504605,
	“expense_category_id”: 701315,
	“spent_at”: “Thu, 08 Sep 2011”
	}
}

Avatar

For anyone who wants to know, the following is what you should post over:

{ "expense": {
	{
	“notes”: “Buy Valentine’s Day chocolates for Harvest”,
	“total_cost”: 11.34,
	“project_id”: 1504605,
	“expense_category_id”: 701315,
	“spent_at”: “Thu, 08 Sep 2011”
	}
}

Notice that total-cost because total_cost and that the “expense” item is inside a pair of braces.

 

[ Please sign up to post a comment. ]