2016-08-02 120 views
2

有沒有人有使用Google Apps腳本對QuickBooks API進行POST的工作示例?使用Google Apps腳本的QuickBooks API POST

我試圖創建一個使用QuickBooks的API的估計,但是雖然請求主體的API資源管理器下面的作品,從Google Apps腳本中,我得到:

Error: Fetch failed, code: 400, message: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Unrecognized token 'Line': was expecting ('true', 'false' or 'null')\n specified is unsupported or invalid","code":"2010"}],"type":"ValidationFault"},"time":"2016-08-02T09:51:28.917-07:00"} (line 195, file "Tests") 

但我不明白爲什麼該API需要一個布爾值而不是「行」鍵。

這是我把它定義爲在代碼中的POST有效載荷:

var payload = { 

    "Line": [ 
     { 
     "Id": "3", 
     "LineNum": 1, 
     "Amount": 10, 
     "DetailType": "SalesItemLineDetail", 
     "SalesItemLineDetail": { 
      "ItemRef": { 
      "value": "2", 
      "name": "Hours" 
      }, 
      "UnitPrice": 10, 
      "Qty": 2 
     } 
     }, 
     { 
     "Amount": 10, 
     "DetailType": "SubTotalLineDetail", 
     "SubTotalLineDetail": {} 
     } 
    ],  
    "TxnTaxDetail": { 
     "TotalTax": 0 
    }, 
    "CustomerRef": { 
     "value": "1", 
     "name": "Mr Blobby" 
    }, 
    "CustomerMemo": { 
     "value": "Thank you for your business and have a great day!" 
    }, 
    "TotalAmt": 31.5, 
    "ApplyTaxAfterDiscount": false, 
    "PrintStatus": "NeedToPrint", 
    "EmailStatus": "NotSet", 
    } 

    var companyId = PropertiesService 
    .getUserProperties() 
    .getProperty('QuickBooks.companyId') 

    var url = 'https://quickbooks.api.intuit.com/v3/company/' + companyId + '/estimate' 

    var options = { 
    headers: { 
     'Accept': 'application/json' 
    }, 
    contentType: 'application/json', 
    method: 'post', 
    payload: payload, 
    muteHttpExceptions: true, 
    } 

    var service = OAuth1_.getService(); 

    var response = service.fetch(url, options) 
+0

你能告訴我們你UrlFetchApp作出完整的調用? –

+0

+ Dimu設計 - 添加抓取 –

回答

0

你需要把它傳遞給OAuth.fetch()調用之前字符串化整個有效載荷。

所以

var payload = JSON.stringify({ 
    "Line": [ 
    { 
     "Id": "3", 
     . 
     . 
})