[英]Smartsheet Webhook error
i am trying to create a webhook from one of my applications in php using curl 我正在尝试使用curl在php中从我的一个应用程序创建一个webhook
here is the piece of code i am using (my token is correct and i own the 6642490389358468 sheet) 这是我正在使用的一段代码(我的令牌是正确的,我拥有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;
}
but i get the following response 但我得到以下回应
{
"errorCode": 1004,
"message": "You are not authorized to perform this action.",
"refId": "x2kcvthuyfs8"
}
can you help me troubleshoot that? 你能帮我解决一下吗? am i missing somehing?
我想念东西吗?
There is one small error in the code—you need to pass a "name" property back with your jsonData array. 代码中有一个小错误-您需要将jsonData数组传递回“ name”属性。
Regarding the authorization issue, I was able to use your exact code with my Smartsheet credentials to successfully create a webhook on a sheet that I created. 关于授权问题,我能够将您的确切代码与我的Smartsheet凭据配合使用,以在我创建的工作表上成功创建Webhook。 Double-check that your Access Token is working properly (or you can issue a brand new one) by using it to do another API call like a getSheet.
通过使用访问令牌执行另一个API调用(如getSheet),来仔细检查您的访问令牌是否正常工作(或者您可以发行一个全新的令牌)。 If the Access Token works, then the issue is with permissions on the sheet you are trying to add a webhook to.
如果访问令牌有效,则问题出在您要向其添加Webhook的工作表上的权限上。 Make sure you have 'Owner' or 'Admin' status on the sheet and copy the sheet ID over again.
确保工作表上具有“所有者”或“管理员”状态,然后再次复制工作表ID。
I can confirm that the code works with the addition of the 'name' property. 我可以确认代码与添加的'name'属性一起工作。
Thank you all, 谢谢你们,
now it works, i did not include the ADMIN_WEBHOOKS access scope when asked for my $token, and of course i forgot the "name" property !! 现在可以正常工作了,当我询问$ token时,我没有包括ADMIN_WEBHOOKS访问范围,当然我也忘记了“名称”属性!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.