Trying to update a cell in a row with PowerShell by passing a variable
This works okay:
$Headers = @{
Authorization = "Bearer ***********"
}
$uri = "https://api.smartsheet.com/2.0/sheets/5034086415787908/rows"
$body = '[{"id": "5257700085983108", "cells": [{"columnId": "853109098473348","value": true}]}]'
Invoke-RestMethod -Method put -Uri $uri -Headers $headers -body $body
But this doesn't work:
$rowid = "5257700085983108"
$body = '[{"id": $rowid, "cells": [{"columnId": "853109098473348","value": true}]}]'
Error:
Invoke-RestMethod : {
"errorCode" : 1008,
"message" : "Unable to parse request. The following error occurred: Field \"null\" was not parsable. Unrecognized token '$rowid': was expecting ('true', 'false' or 'null')\n
How do I pass a variable in the body of the API?
Thanks.
Answers
-
Hi @Alen,
It looks like one of the "$rowID" values in your call isn't expected - probably this is the one after the "id": field which is expecting "true", "false" or "null" values instead of "$rowID". There should also be specific reference to the specific line of command and column that are causing the API call to fail.
I also believe that PowerShell requires double quotes to handle the variable in the string:
$body = "[{"id": $rowid, "cells": [{"columnId": "853109098473348","value": true}]}]"
If this doesn't look correct or can't figure the actual value to be inserted, I'd suggest reviewing the specific method syntax required for this action in the API Documentation.
If you'd need further advise, please make sure to include a full capture of the logs returned by the API including the specific line and column triggering this error.
I hope that this can be of help.
Cheers!
Julio
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 62.3K Get Help
- 364 Global Discussions
- 199 Industry Talk
- 428 Announcements
- 4.4K Ideas & Feature Requests
- 136 Brandfolder
- 127 Just for fun
- 128 Community Job Board
- 444 Show & Tell
- 28 Member Spotlight
- 1 SmartStories
- 283 Events
- 35 Webinars
- 7.3K Forum Archives