curlterminalsmartsheet-apismartsheet-java-sdk-v2

cURL command in smartsheet


when I use the following curl command: (the tokens are invalid don't worry)

curl https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool

I get a bunch of data looking like this:

 {
        "id": 1888886872926084,
        "index": 0,
        "primary": true,
        "title": "Primary Column",
        "type": "TEXT_NUMBER",
        "width": 150
    },
    {
        "id": 6392486500296580,
        "index": 1,
        "title": "Column2",
        "type": "TEXT_NUMBER",
        "width": 150
    },
    {
        "id": 4140686686611332,
        "index": 2,
        "title": "Column3",
        "type": "TEXT_NUMBER",
        "width": 150
    },
    {
        "id": 8644286313981828,
        "index": 3,
        "title": "Column4",
        "type": "TEXT_NUMBER",
        "width": 150
    },
    {
        "id": 481511989372804,
        "index": 4,
        "title": "Column5",
        "type": "TEXT_NUMBER",
        "width": 150
    },
    {
        "id": 4985111616743300,
        "index": 5,
        "title": "Column6",
        "type": "TEXT_NUMBER",
        "width": 150
    }
],
"createdAt": "2016-07-07T14:44:38Z",
"dependenciesEnabled": false,
"effectiveAttachmentOptions": [
    "FILE",
    "ONEDRIVE",
    "GOOGLE_DRIVE",
    "EVERNOTE",
    "BOX_COM",
    "EGNYTE",
    "DROPBOX"
],
"ganttEnabled": false,
"id": 5848567060424580,
"modifiedAt": "2016-07-07T15:22:53Z",
"name": "JagTestSheet",
"permalink": "https://app.smartsheet.com/b/home?lx=PoM3LKb9HF6g_jsJ9JoWwg",
"resourceManagementEnabled": false,
"rows": [
    {
        "cells": [
            {
                "columnId": 1888886872926084,
                "displayValue": "234",
                "value": 234.0
            },
            {
                "columnId": 6392486500296580,
                "displayValue": "657",
                "value": 657.0
            },
            {
                "columnId": 4140686686611332,
                "displayValue": "875",
                "value": 875.0
            },
            {
                "columnId": 8644286313981828
            },
            {
                "columnId": 481511989372804
            },
            {
                "columnId": 4985111616743300
            }
        ],

Now, I know its showing every row of data for the columns that are filled, but i wanted to know if there is anyway i could simplify this only to spit out what i need, for example only displayValue for the columns in which data are in ? Any help would be awesome thanks!


Solution

  • You will need a programming language to logically manipulate the data that is coming back from Smartsheet. I would recommend doing this with one of the existing SDK's that Smartsheet offers. Smartsheet currently has SDK's for Java, C#, Javascript, Python and PHP all listed on this page.

    That said, you can also accomplish this task with bash using curl, grep, cut or jq.

    First you can you grep to limit the result to only displayValue.

    curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool | grep displayValue
    

    Then you can take this a step further and only display the values by using cut:

    curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool | grep displayValue | cut -d: -f2
    

    You could also use a tool such as jq which has the ability to work with json output. You could use a command like the following to fetch only the displayValue.

    curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | jq '.rows[].cells[].displayValue'
    

    Then you can take this a step further and remove the null results:

    curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | jq '.rows[].cells[] | select(.displayValue != null).displayValue'