簡體   English   中英

Smartsheet Webhook錯誤

[英]Smartsheet Webhook error

我正在嘗試使用curl在php中從我的一個應用程序創建一個webhook

這是我正在使用的一段代碼(我的令牌是正確的,我擁有6642490389358468表)

function setWebHook($token){
            // API Url
            // BASE_API_URL = "https://api.smartsheet.com/2.0/";
            $url = self::BASE_API_URL. "webhooks";
            $headers = array(
              "Authorization: Bearer ". $token,
              "Content-Type: application/json"
             );
            //The JSON data.
            $jsonData = array(
                "callbackUrl"=>"https://www.example.com/myapp/test",
                "scope"=>"sheet",
                "scopeObjectId"=>6642490389358468,
                "version"=>1,
                "events"=>[ "*.*" ]
            );
            //Initiate cURL.
            $ch = curl_init($url);
            //Encode the array into JSON.
            $jsonDataEncoded = json_encode($jsonData);
            //Tell cURL that we want to send a POST request.
            curl_setopt($ch, CURLOPT_POST, 1);
            //Attach our encoded JSON string to the POST fields.
            curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
            //Set the content type to application/json
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            //Execute the request
            $result = curl_exec($ch);
            if (curl_errno($ch)) {
                $apiResponse = "Oh No! Error: " . curl_error($ch);
            } else {
                // Assign response to variable
                $apiResponse = json_decode($result);
                curl_close($ch);
            }
            return $apiResponse;
        }

但我得到以下回應

{
    "errorCode": 1004,
    "message": "You are not authorized to perform this action.",
    "refId": "x2kcvthuyfs8"
}

你能幫我解決一下嗎? 我想念東西嗎?

代碼中有一個小錯誤-您需要將jsonData數組傳遞回“ name”屬性。

關於授權問題,我能夠將您的確切代碼與我的Smartsheet憑據配合使用,以在我創建的工作表上成功創建Webhook。 通過使用訪問令牌執行另一個API調用(如getSheet),來仔細檢查您的訪問令牌是否正常工作(或者您可以發行一個全新的令牌)。 如果訪問令牌有效,則問題出在您要向其添加Webhook的工作表上的權限上。 確保工作表上具有“所有者”或“管理員”狀態,然后再次復制工作表ID。

我可以確認代碼與添加的'name'屬性一起工作。

謝謝你們,

現在可以正常工作了,當我詢問$ token時,我沒有包括ADMIN_WEBHOOKS訪問范圍,當然我也忘記了“名稱”屬性!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM