I'm constructing my own HTTP requests for use with the QuickBooks Online v3 REST API, 'rolling my own' in the words of Keith Palmer - Consolibyt's response to this post.
I particular, I want to create, update, and delete transactions and names using JSON-formatted request bodies. The documentation is very sparse with JSON examples, so this is all I could find:
{
...
"domain":"QBO"
"sparse":{"true","false"}
...
}
The API gives XML examples for creating, updating, and deleting transactions, and I have been able to use those in the API explorer successfully. (For other reasons, though, I don't want to work with XML. I want to work in JSON.)
In trying to figure out how to do the same thing with JSON, I did a read of an existing JournalEntry (in the API Explorer), getting this response and planning to build the request body starting from here:
{
"JournalEntry": {
"Adjustment": false,
"domain": "QBO",
"sparse": false,
"Id": "1056",
"SyncToken": "2",
"MetaData": {
"CreateTime": "2014-02-07T13:21:51-08:00",
"LastUpdatedTime": "2014-02-07T13:29:53-08:00"
},
"DocNumber": "4",
"TxnDate": "2014-02-08",
"CurrencyRef": {
"value": "USD",
"name": "United States Dollar"
},
"Line": [
{
"Id": "0",
"Description": "test entry",
"Amount": 102.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "57",
"name": "Miscellaneous Income"
}
}
},
{
"Id": "1",
"Description": "test entry (UPDATED!)",
"Amount": 252.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Debit",
"AccountRef": {
"value": "29",
"name": "6240 Miscellaneous"
}
}
},
{
"Id": "2",
"Description": "test entry",
"Amount": 150.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "82",
"name": "12100 Inventory Asset"
}
}
}
]
},
"time": "2014-02-07T14:21:16.181-08:00"
}
Here's the request body I'm using for an Update operation (on the same JournalEntry page of the API Explorer) -- note that I'm only changing the DocNumber (from 4 to 12345):
{
"Adjustment": false,
"domain": "QBO",
"sparse": false,
"Id": "1056",
"SyncToken": "2",
"MetaData": {
"CreateTime": "2014-02-07T13:21:51-08:00",
"LastUpdatedTime": "2014-02-07T13:29:53-08:00"
},
"DocNumber": "12345",
"TxnDate": "2014-02-08",
"CurrencyRef": {
"value": "USD",
"name": "United States Dollar"
},
"Line": [
{
"Id": "0",
"Description": "test entry",
"Amount": 102.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "57",
"name": "Miscellaneous Income"
}
}
},
{
"Id": "1",
"Description": "test entry (UPDATED!)",
"Amount": 252.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Debit",
"AccountRef": {
"value": "29",
"name": "6240 Miscellaneous"
}
}
},
{
"Id": "2",
"Description": "test entry",
"Amount": 150.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "82",
"name": "12100 Inventory Asset"
}
}
}
]
}
Here's the Response Body I get back:
{"Fault":{"Error":[{"Message":"An application error has occurred while processing your request","Detail":"System Failure Error: null","code":"10000"}],"type":"SystemFault"},"time":"2014-02-07T14:36:18.888-08:00"}
I'm also trying a sparse update, as per these instructions, just to keep things simple. The request body:
{
"sparse": "true",
"Id": "1056",
"SyncToken": "2",
"DocNumber": "12345"
}
The response body I get back (in bright red):
{"Fault":{"Error":[{"Message":"An application error has occurred while processing your request","Detail":"System Failure Error: null","code":"10000"}],"type":"SystemFault"},"time":"2014-02-07T14:05:05.197-08:00"}
I have a feeling the problem here is something small. Can you point out what it is? Alternatively, if you have a working example of a JSON request body (for create, update, and delete operations of a transaction, ideally), that would be very helpful too (as hopefully I could use it as a template).
You need to add Accept : application/json to your header.