Export Smartsheet as CSV using API - "media type not supported"

I'm able to export a smartsheet document as JSON with the API, however, our endpoint doesn't support nested data. So I'd like to get it either as flattened JSON or CSV.

Sample #4 here shows the CSV option:

// Sample 4: Get sheet as CSV
curl https://api.smartsheet.com/2.0/sheets/{sheetId} \
-H "Authorization: Bearer ll352u9jujauoqz4gstvsae05" \
-H "Accept: text/csv" \
-o output.csv

When I try it with the terminal or Postman it returns, "Invalid Accept header. Media type not supported."

Am I doing something wrong or is it no longer supported?

Otherwise I'm going to have to write something to reformat the JSON for our use case.

Thank you

Best Answer

  • bsikes
    bsikes ✭✭✭✭
    Answer ✓

    I'm able to export a sheet to CSV using a PowerShell script and the sample code provided for the API. One thing I did notice, was that I also received the "Invalid Accept header. Media type not supported." message when I didn't have the correct Sheet ID being used. So even though the message points to your Accept header, that may not be where the problem is.

Answers

  • bsikes
    bsikes ✭✭✭✭
    Answer ✓

    I'm able to export a sheet to CSV using a PowerShell script and the sample code provided for the API. One thing I did notice, was that I also received the "Invalid Accept header. Media type not supported." message when I didn't have the correct Sheet ID being used. So even though the message points to your Accept header, that may not be where the problem is.

  • Did you open and verify the contents of the csv file? When I run the example without the -o flag, it returns the error in the terminal. When I run it with the -o flag, it just exports the same error to the created .csv file but the file doesn't contain the desired data.

    I just went ahead and created the middleware to reformat the json but am curious if this csv output option works.

  • bsikes
    bsikes ✭✭✭✭

    Yep, CSV file had the correct content. For what it's worth, here's the PowerShell syntax I'm using that is working:


  • Figured it out and you were right. I was using the long string of text at the end of the permalink url, the one that contains numbers and letters, and not the shorter 16-digit sheetID which is all numbers.

    I don't know why both work when returning json but only the sheetID works with csv.

    Thanks for your help!