I want to attach a simple URL to a sheet or row in a sheet using cURL API. The Smartsheet documentation only explains how to attach a file. I have tried with a request body and adjusting the headers to somehow attach a URL but failed as I don't know how to adjust the headers or compose the body.
From Smartsheet API Docs:
Attach File or URL to Sheet Attaches a file to the sheet. The URL can be any of the following:
Normal URL (attachmentType "LINK")
Box.com URL (attachmentType "BOX_COM")
Dropbox URL (attachmentType "DROPBOX")
curl https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments \
-H "Authorization: Bearer JKlMNOpQ12RStUVwxYZAbcde3F5g6hijklM789" \
-H "Content-Type: application/msword" \
-H 'Content-Disposition: attachment; filename="ProgressReport.docx"' \
-H "Content-Length: FILE_SIZE" \
-X POST \
--data-binary @ProgressReport.docx
Whenever I'm trying to solve a problem like the one you've described, I often find it helpful to look at how the item I'm trying to create is represented in a "Get item" API response -- then I can try to use that same data structure/contents in a "Create item" API request...99% of the time this approach is successful. I'll explain this process in the context of answering your question.
First, I logged into the Smartsheet web app and added a URL attachment to a row.
Next, I sent a List Attachments API request, so I could see the properties that got set for URL attachment when I added it via the web app.
List Attachments request:
List Attachments response:
Of the properties present in this API response, only 3 of them actually describe the URL attachment itself:
name
URL
attachmentType
Now that I know what properties get set for a URL Attachment (that's added via the app), I'm going to try issuing an Attach URL API request that sets those 3 properties for the URL I want to attach to the sheet.
Attach URL (to sheet) request:
In cURL, this request would be specified as follows:
Upon issuing this request, I get the following response back:
Attach URL response:
Bingo! -- the URL Attachment was successfully added to the sheet.
Please note that the sample code above adds the URL attachment to the Sheet. To add a URL attachment to a Row, the request URL would need to include
/rows/{rowId}
as shown here: