如何使用JSON正文创建QBO v3 API创建,更新和删除请求

时间:2014-02-07 22:35:31

标签: json quickbooks intuit-partner-platform quickbooks-online

我正在构建我自己的HTTP请求,以便与QuickBooks Online v3 REST API一起使用,用Keith Palmer的话来“滚动我自己” - Consolibyt对this post的回应。

我特别想要使用JSON格式的请求主体创建,更新和删除事务和名称。使用JSON示例的文档非常稀疏,因此我可以找到this

{
    ...
    "domain":"QBO"
    "sparse":{"true","false"}
    ...
}

API为creatingupdatingdeleting交易提供了XML示例,并且我已成功地在API资源管理器中使用这些示例。 (但是出于其他原因,我不想使用XML。我想使用JSON。)

在试图弄清楚如何使用JSON做同样的事情时,我读了一个现有的JournalEntry(在API资源管理器中),得到了这个响应并计划从这里开始构建请求体:

{
  "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"
}

这是我用于更新操作的请求正文(在同一JournalEntry page of the API Explorer上) - 请注意,我只是更改了DocNumber(从4到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"
          }
        }
      }
    ]
}

这是我回复的响应主体:

{"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"}

我也在尝试使用these instructions进行稀疏更新,只是为了简单起见。请求正文:

{
    "sparse": "true",
    "Id": "1056",
    "SyncToken": "2",
    "DocNumber": "12345"
}

我回来的响应体(鲜红色):

{"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"}

我觉得这里的问题很小。你能指出它是什么吗?或者,如果您有一个JSON请求体的工作示例(理想情况下用于事务的创建,更新和删除操作),那也非常有用(希望我可以使用它作为模板)。

1 个答案:

答案 0 :(得分:4)

您需要在标题中添加Accept:application / json。