using CURL and windows batch file to POST many rows at once

jurivera88201
jurivera88201 ✭✭
edited 12/09/19 in API & Developers

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

  • dAVE Inden
    dAVE Inden Employee

    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:

    https://stackoverflow.com/questions/17743757/how-to-concatenate-strings-in-windows-batch-file-for-loop