2016-08-02 20 views
2

Hat jemand ein funktionierendes Beispiel für die Durchführung eines POST für die QuickBooks-API mit Google Apps Script?QuickBooks-API-POST mit Google Apps-Skript

Ich versuche, eine Schätzung unter Verwendung der API Quickbooks, aber zu schaffen, obwohl die Anfrage Körper in der API-Explorer arbeitet unten, von innen Apps Script ich:

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") 

Aber ich kann nicht sehen, warum Die API erwartet einen Booleschen Schlüssel anstelle des Schlüssels "Line". Diese

ist, wie ich es als POST Nutzlast im Code definieren:

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

Können zeigen Sie uns den vollen Anruf, den Sie UrlFetchApp gemacht? –

+0

+ Dimu Designs - Fetch hinzugefügt –

Antwort

0

Sie müssen die gesamte Nutzlast stringify, bevor es den OAuth.fetch() Aufruf übergeben.

So

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