2016-08-14 14 views
1

私はかなり新しいGoogle Apps Scriptです。私はパブリックAPIからデータを取得するためのスクリプトを作成しようとしています。私は、パラメータを渡す必要がありますが、APIのdocumenation情報は、このようにアクセスできることを示しApps ScriptAppsスクリプトのパラメータをcUrlに渡す

でそれを行う方法を見つけ出すことはできません。

curl -H "Content-Type: application/json" -X GET 
--header "X-PW-AccessToken:<TOKEN>" \ 
--header "X-PW-Application:developer_api" \ 
--header "X-PW-UserEmail:<USER_EMAIL_ADDRESS>" \ 
-d '{"name":"My Lead","email":{"email":"[email protected]","category":"work"}}' 

私はApps Scriptでこの機能を設定しています。

function myFunction() { 
    var url = "https://api.prosperworks.com/developer_api/v1/leads/search"; 
    var fetchParameters = {}; 
    fetchParameters.method = "post"; 
    fetchParameters.contentType = "application/json"; 
    fetchParameters.headers = { 
     "X-PW-AccessToken": <TOKEN>, 
     "X-PW-Application": "developer_api", 
     "X-PW-UserEmail": <USER_EMAIL_ADDRESS> 
    }; 
    fetchParameters.muteHttpExceptions = true; 
    fetchParameters.payload = {"name":"My Lead","email":{"email":"[email protected]","category":"work"}}; 

    var response = UrlFetchApp.fetch(url, fetchParameters); 
    var dataAll = JSON.parse(response.getContentText()); 
} 

それが値を渡す方法であるように見えたので、私はfetchParameters.payloadを追加しましたが、私はJSONを解析すると、このエラーが出る:

Execution failed: SyntaxError: Unexpected token: < 

私がfetchParameters.payloadをコメントアウトすると、正常に動作しますが、どのパラメータも(明らかに)考慮しません。

私は試してみました:fetchParameters.dfetchParameters.dataなどがありますが、何も動作していないようです。

答えて

1

APIドキュメントを示しています

-X GET 

あなたのコードが使用しています:

fetchParameters.method = "post"; 

fetchParameters.method = "get"; 
にそれを変更してみてください
関連する問題