Smartsheet Attachment through API - Simple CSV

110 views Asked by At

I am struggling with the webmethod.IO workflow to send a CSV file to the Smartsheet attachment. It looks like I am missing something. Can anyone please share the Postman collection?

File: C:\temp\master.csv

HTTP POST: https://api.smartsheet.com/2.0/sheets/{SheetID}/attachments

I tried to set the filename and path. Looks like it requires passing the memory stream and size of the file. My CSV file is only 20 KB.

1

There are 1 answers

0
Kim Brandl On

I've never used webmethods.io, but based on their documentation it looks like the only add attachment operation it supports is Attach File to Row.

The operation to attach a file to a row with the Smartsheet API is:

POST https://api.smartsheet.com/2.0/sheets/sheetId/rows/rowId/attachments

In this endpoint, replace sheetId with the ID of the sheet and replace rowId with the ID of the row. You can determine both values by using the Smartsheet web app.

  • To find Sheet ID: open the sheet and choose Properties from the File menu along the top of the screen.
  • To find Row ID: click on the left-most edge of the row (to the left of the row #) to select the row, then right-click and choose Properties from the popup menu.

You'll need to set 4 HTTPS headers for this request:

Authorization: Bearer YOUR_ACCESS_TOKEN HERE
Content-Type: text/csv
Content-Disposition: attachment; filename="master.csv"
Content-Length: NUMBER_OF_CHARACTERS_IN_YOUR_CSV_FILE_HERE

In these headers, you'll need to replace YOUR_ACCESS_TOKEN HERE with the value of your API Access Token and replace NUMBER_OF_CHARACTERS_IN_YOUR_CSV_FILE_HERE with a numeric value that represents the number of characters (including all commas) in your csv file.

For example, here are the headers that I set when testing the operation in Postman:

Postman add attachment headers

The contents of my csv file is simply: this,is,a,test -- which is 14 characters in length (the value of the Content-Length header in my request).

Finally, you'll set the body of the request to the contents of your file (in binary format). When I tested this operation in Postman, I was able to select binary format for the body, and then just choose my file via the UI -- so I didn't have to manually convert my file contents to binary format -- Postman did it for me.

Postman add attachment

In Postman, I pressed the Select file button shown in the screenshot above and then chose the file from my machine that I wanted to upload:

Postman file selected

I imagine that webmethods.io is the same -- i.e., I'm guessing you can just choose/upload the file via the webmethods.io user interface.


That all said, if the webmethods.io documentation is out of date and it does actually support the Attach File to Sheet operation, then everything would be the same as I've described above, except that there would be no rowId at the end of the endpoint:

https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments