using CURL and windows batch file to POST many rows at once
Hi guys,
So I’ve been playing on & off with Smartsheet API and have been able to post a row on a sheet succesfully using CURL on Windows via a batch file.
Now I need to do the same but for multiple rows from a CSV file. I read that I could do so if I insert an array variable per column within the json part of the CURL command. But, i don’t know how to do this in windows batch. Like I need to concatinate the string somehow.
any pointers?
Here is the code:
set c01[0]="0123456"
set c01[1]="0123457"
set c01[2]="0123458"
set c01[3]="0123459"
set c01[4]="0123450"
curl https://api.smartsheet.com/2.0/sheets/350958217883456/rows ^
-H "Authorization: Bearer abc1234bhyt5678poiu09876" ^
-H "Content-Type: application/json" ^
-X POST ^
-d “[{\"toBottom\":true, \"cells\": [{\"columnId\": 949033830246276, \"value\": " %c01 "}]}]"
Comments
-
To POST multiple rows to a sheet at once you need to make sure the body of your request provides an array of Row Objects. Using your example body it would look similar to this:
“[{\"toBottom\":true, \"cells\": [{\"columnId\": 949033830246276, \"value\": " %c01 "}]}, {\"toBottom\":true, \"cells\": [{\"columnId\": 949033830246276, \"value\": " %c01 "}]}, {\"toBottom\":true, \"cells\": [{\"columnId\": 949033830246276, \"value\": " %c01 "}]}, {\"toBottom\":true, \"cells\": [{\"columnId\": 949033830246276, \"value\": " %c01 "}]}]"
This will add a total of 4 rows to the sheet with the same data in each column.
As for doing this in Windows batch, I'm not sure. Concatenating the string of values to create the request body you need seems like a good approach. Doing some searching I found a post on StackOverflow about that here:
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.8K Get Help
- 437 Global Discussions
- 138 Industry Talk
- 470 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 65 Community Job Board
- 486 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives