我有一個關於發送的Web API調用sendgrid一個問題:工作的API調用和JSON格式獲取數據回
以下文檔用於檢索高級統計:
http://sendgrid.com/docs/API_Reference/Web_API/Statistics/statistics_advanced.html
在「呼叫」部分,下面已經提到:
POST https://api.sendgrid.com/api/stats.getAdvanced.json
POST Data api_user=your_sendgrid_username&api_key=your_sendgrid_password&start_date=2013-01-01&end_date=2013-01-02&data_type=global
我明白,我需要使用CFHTTP的Web API調用和I S應該是 在cfhttp
標記的url參數 中提及"https://api.sendgrid.com/api/stats.getAdvanced.json"
。
哪裏需要提及api_user和api_key部分?我知道我會在 的地方提到我的sendgrid帳號的用戶名和密碼。
爲了便於說明,讓我們考慮下面的虛擬值:
api_user = stack
api_key = 123456
請讓我知道。我正在嘗試發送API調用,並以JSON格式返回數據。
感謝
未遂#1
我使用下面的代碼:
<cfhttp url="https://api.sendgrid.com/api/stats.getAdvanced.json" method="POST" result="returnStruct">
<cfhttpparam name="api_user" value="stack" type="formfield">
<cfhttpparam name="api_key" value="123456" type="formfield">
<!--- <cfhttpparam name="days" value="5" type="formfield"> --->
<cfhttpparam name="start_date" value="2013-12-06" type="formfield">
<!--- <cfhttpparam name="end_date" value="2013-12-09" type="formfield"> --->
</cfhttp>
<cfdump var="#returnStruct#">
我得到的結構形式以下錯誤。我上面做錯了什麼?請檢查我的代碼如下。
Charset [empty string]
ErrorDetail [empty string]
Filecontent {"error": "error in data_type: data_type is required"}
Header HTTP/1.1 400 Bad Request Content-Type: text/html Connection: close Date: Tue, 10 Dec 2013 06:21:19 GMT Server: nginx/1.4.2
Mimetype text/html
Responseheader
struct
Connection close
Content-Type text/html
Date Tue, 10 Dec 2013 06:21:19 GMT
Explanation Bad Request
Http_Version HTTP/1.1
Server nginx/1.4.2
Status_Code 400
Statuscode 400 Bad Request
Text YES
我想知道,它指的是哪個data_type
,如文檔不談論它。
謝謝您的回答。你能否檢查我的原始帖子中「我嘗試#1」部分提到的錯誤。謝謝 – Jack
文檔確實討論了它「data_type」 - 它是您發佈的文檔鏈接中的第一個參數。這是一個必需的參數,以便解釋您收到的錯誤。 – existdissolve
@jack你有沒有找到你的解決方案,請分享...謝謝 –