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
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 139 Industry Talk
- 471 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 497 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives