smartsheet 中的 cURL 命令
cURL command in smartsheet
当我使用以下 curl 命令时:(令牌无效,不用担心)
curl https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool
我得到一堆这样的数据:
{
"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
}
],
现在,我知道它显示了已填充列的每一行数据,但我想知道是否可以简化它以仅吐出我需要的内容,例如仅显示列的 displayValue哪些数据在?任何帮助都会非常感谢!
您将需要一种编程语言来逻辑操作从 Smartsheet 返回的数据。我建议使用 Smartsheet 提供的现有 SDK 之一来执行此操作。 Smartsheet 目前有 Java、C#、Javascript、Python 和 PHP 的 SDK,它们都列在 this page.
上
也就是说,您也可以 bash 使用 curl、grep、cut 或 jq 完成此任务。
首先,您可以 grep
将结果限制为仅显示值。
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool | grep displayValue
然后您可以更进一步,仅使用 cut
:
显示值
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool | grep displayValue | cut -d: -f2
您还可以使用 jq 等工具,它能够处理 json 输出。您可以使用如下命令仅获取 displayValue。
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | jq '.rows[].cells[].displayValue'
然后您可以更进一步,删除空结果:
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | jq '.rows[].cells[] | select(.displayValue != null).displayValue'
当我使用以下 curl 命令时:(令牌无效,不用担心)
curl https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool
我得到一堆这样的数据:
{
"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
}
],
现在,我知道它显示了已填充列的每一行数据,但我想知道是否可以简化它以仅吐出我需要的内容,例如仅显示列的 displayValue哪些数据在?任何帮助都会非常感谢!
您将需要一种编程语言来逻辑操作从 Smartsheet 返回的数据。我建议使用 Smartsheet 提供的现有 SDK 之一来执行此操作。 Smartsheet 目前有 Java、C#、Javascript、Python 和 PHP 的 SDK,它们都列在 this page.
上也就是说,您也可以 bash 使用 curl、grep、cut 或 jq 完成此任务。
首先,您可以 grep
将结果限制为仅显示值。
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool | grep displayValue
然后您可以更进一步,仅使用 cut
:
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | python -m json.tool | grep displayValue | cut -d: -f2
您还可以使用 jq 等工具,它能够处理 json 输出。您可以使用如下命令仅获取 displayValue。
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | jq '.rows[].cells[].displayValue'
然后您可以更进一步,删除空结果:
curl -s https://api.smartsheet.com/2.0/sheets/5848367060424580 -H "Authorization: Bearer 21txb6n2silf6dhsil8g9jxtdu" | jq '.rows[].cells[] | select(.displayValue != null).displayValue'