I have a php page that lists the smartsheet content for different users. It populates a table with information like the name of a job, the start date and delivery date. But I would also like the users to be able to tick a checkbox when the job is done.
When the checkbox is checked another (very rudimentary) page is called to store the new value to the smartsheet.
This page is triggered by a basic get command like this:
http://myurl/index.php?colId=XXX&rowId=YYY&status=checked
Where the variables used are:
colId=The ID of the column to be changed
rowId=The ID of the row to be changed
checked=If the checkbox is checked
status=The value stored in the smartheet
(1 for a checked checkbox and '' for an unchecked checkbox)
This is the code of index.php (stolen from this post):
$inputToken = "myInputToken";
$colId=$_GET['colId'];
$rowId=$_GET['rowId'];
if($_GET['status'] == "checked"){
$status='1';
}
else{
$status='';
}
$ch = curl_init("https://api.smartsheet.com/1.1/row/".$rowId./cells");
$header = array("Authorization: Bearer ".$inputToken,
"Content-Type: application/json",
"Assume-User: myName%40myDomainName");
$fields = '[{"columnId": $colId, "value": "'.$status.'", "displayValue": "'.$status.'"}]';
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$result = curl_exec($ch);
print_r($result);
The "input token" is generated by the same email that is used as the "Assume-User" email. And I'm able to change the values in a regular smartsheet when I'm logged in. But still I get this error when I run the webpage:
{"errorCode":1030,"message":"You are unable to assume the user specified."}
Does anyone know what I have done wrong?
Any help will be very appreciated!
There are two ways to login as a user. First you can login directly by using the token for that users account. The headers would look like:
$header = array('Authorization: Bearer '.$userToken,
"Content-Type: application/json");
The second option is to use an administrator account to login as another user. To do this you can use the assume-user header along with the administrator's token. The headers would look like:
$header = array('Authorization: Bearer '.$adminToken,
'Content-Type: application/json',
'Assume-User: someUser%40someDomain.com');
The documentation for the assume-user can be found here.