What's the easiest way to grab all specific JSON data from a Smartsheet JSON?
Best Answer
-
Jeff Reisman ✭✭✭✭✭✭
Are you putting the sheetId value in place of{sheetId}?
When I run that as a GET in Postman, I get an array of each column ID with the name and type:
Regards,
Jeff Reisman,IT Business Analyst & Project Coordinator,Mitsubishi Electric Trane US
链接:Smartsheet Functions Help Pages链接:Smartsheet Formula Error Messages
If my answer helped solve your issue, please mark it as accepted so that other users can find it later. Thanks!
Answers
-
sharkasits ✭✭✭✭
@DougSmartsheetDevI don't use Python for this, so I can't give you specifics on that, bur from the API side you'll use a GET athttps://api.smartsheet.com/2.0/sheets/<
> to pull the data. If you don't know the column index you can look for the column title where the JSON element is
columns.<
>.title Once you know the column index, all the values for that column will be in the JSON element
rows.<
>.cells.<
>.value Sorry I can't help with the specific Python, but I hope that helps.
-
Jeff Reisman ✭✭✭✭✭✭
Start with theSmartsheet API 2.0 / SDK guide.
First, get your API Auth Bearer Token from the admin app.
Then you need to isolate your sheet id:
GET /sheets https://api.smartsheet.com/2.0/sheets response = smartsheet_client.Sheets.list_sheets(include_all=True) sheets = response.data Response sample: { "pageNumber": 1, "pageSize": 50, "totalPages": 25, "totalCount": 136, "data": [ { "id": 0, "accessLevel": "ADMIN", "createdAt": "2019-08-24T14:15:22Z", "modifiedAt": "2019-08-24T14:15:22Z", "name": "string", "permalink": "string", "version": 0, "source": { "id": 0, "type": "string" } } ] }
Then you need to GET the list of columns and find the column Id you're looking for:
https://api.smartsheet.com/2.0/sheets/ {sheetId} / columns response = smartsheet_client.Sheets.get_columns( 9283173393803140, # sheet_id include_all=True) columns = response.data Sample Response: { "pageNumber": 1, "pageSize": 50, "totalPages": 25, "totalCount": 136, "data": [ { "id": 0, "index": 0, "symbol": "string", "title": "string", "type": "ABSTRACT_DATETIME", "validation": true } ] }
Then you need to GET the row data from that column:
That's detailed here in the API/SDK guide:https://smartsheet.redoc.ly/tag/rows#operation/row-get
You could also use theSmartsheet Live Data Connectorto query the sheet you want and use some other app to parse the column data to json.
Regards,
Jeff Reisman,IT Business Analyst & Project Coordinator,Mitsubishi Electric Trane US
链接:Smartsheet Functions Help Pages链接:Smartsheet Formula Error Messages
If my answer helped solve your issue, please mark it as accepted so that other users can find it later. Thanks!
-
Hello Jeff & Shark,
However, when I try to do, https://api.smartsheet.com/2.0/sheets/{sheetId}/columns
I get this:
{
"errorCode": 1006,
"message": "Not Found",
"refId": "6liwku"
}
I can get the sheet but not the columns?
-
Jeff Reisman ✭✭✭✭✭✭
Are you putting the sheetId value in place of{sheetId}?
When I run that as a GET in Postman, I get an array of each column ID with the name and type:
Regards,
Jeff Reisman,IT Business Analyst & Project Coordinator,Mitsubishi Electric Trane US
链接:Smartsheet Functions Help Pages链接:Smartsheet Formula Error Messages
If my answer helped solve your issue, please mark it as accepted so that other users can find it later. Thanks!
-
Jeff,
Appreciate the response!
Yes I am putting the sheetId in place there. I'm able to access the sheet it's when I try to access anything further that I have trouble.
Thankfully,
Doug
-
Jeff Reisman ✭✭✭✭✭✭
Do you have at least editor permissions on the sheet you're trying to pull from? I don't believe your API token can access anything that your account cannot.
Double check that the sheet ID is correct.
I'm assuming you're not using { } curly braces in the URL.
Before the sheet ID, "sheets" should be all lowercase, as should "columns" after the Sheet ID.
Any of the above being wrong will throw an error code 1006 "Not Found".
Regards,
Jeff Reisman,IT Business Analyst & Project Coordinator,Mitsubishi Electric Trane US
链接:Smartsheet Functions Help Pages链接:Smartsheet Formula Error Messages
If my answer helped solve your issue, please mark it as accepted so that other users can find it later. Thanks!
-
Jeff,
- No curly Braces in URL
- sheets is lowercase, get call works for sheet, just stops at the /columns
- sheetId is correct
- Permission level is admin
indebtedly,
Doug
Edit: Embarrassed to say that I had my sheet ID & Linked Values Swapped. The answers provided above worked like a charm. My bad all and thank you.
Categories
You should be able to see this in the Activity Log (if you have access), but the other giveaway will be that will data in the similarly named columns but not the original ones.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]},{"discussionID":107283,"type":"question","name":"Determine all of the workflows a user is assigned to\/included in","excerpt":"Prior to deactivating a Smartsheet user, is there a way to see what workflows they were assigned to across all Smartsheet items? Oftentimes, the employee replacing that user will need to replace them in the workflows. Is there an easy way to do this? Even just knowing what workflows someone is involved in would be VERY…","snippet":"Prior to deactivating a Smartsheet user, is there a way to see what workflows they were assigned to across all Smartsheet items? Oftentimes, the employee replacing that user will…","categoryID":320,"dateInserted":"2023-07-06T15:31:33+00:00","dateUpdated":null,"dateLastComment":"2023-07-07T12:57:30+00:00","insertUserID":163180,"insertUser":{"userID":163180,"name":"mgainey","url":"https:\/\/community.smartsheet.com\/profile\/mgainey","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-07-13T12:46:30+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":45516,"lastUser":{"userID":45516,"name":"Paul Newcome","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Paul%20Newcome","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/082\/nQPUTVFKKWDJ2.jpg","dateLastActive":"2023-07-14T20:36:06+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":43,"score":null,"hot":3377393943,"url":"https:\/\/community.smartsheet.com\/discussion\/107283\/determine-all-of-the-workflows-a-user-is-assigned-to-included-in","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/107283\/determine-all-of-the-workflows-a-user-is-assigned-to-included-in","format":"Rich","lastPost":{"discussionID":107283,"commentID":384139,"name":"Re: Determine all of the workflows a user is assigned to\/included in","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/384139#Comment_384139","dateInserted":"2023-07-07T12:57:30+00:00","insertUserID":45516,"insertUser":{"userID":45516,"name":"Paul Newcome","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Paul%20Newcome","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/082\/nQPUTVFKKWDJ2.jpg","dateLastActive":"2023-07-14T20:36:06+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-07-06T21:09:46+00:00","dateAnswered":"2023-07-06T17:23:30+00:00","acceptedAnswers":[{"commentID":383983,"body":"
Unfortunately there is no way to pull\/generate a report for this. It is a very manual process.<\/p>
<\/p>
Feel free to browse through the Product Ideas tab at the top of this page to see if someone has submitted the enhancement request. If they have, you can add your vote. If they have not, then you can submit it yourself and allow others to add their votes.<\/p>
<\/p>
Either way, it would be great if you could post a link to the enhancement request here so that others searching for the same thing can easily add their votes.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]},{"discussionID":107096,"type":"question","name":"Get a sheet URL with the Sheet ID [API]","excerpt":"I'm using Python and I want to get the URL of a sheet if I know its sheet ID. I try to create a list of hyperlink thru the API. I already have access to the sheet and I could copy the url by hand, but that is not the point.","snippet":"I'm using Python and I want to get the URL of a sheet if I know its sheet ID. I try to create a list of hyperlink thru the API. I already have access to the sheet and I could copy…","categoryID":320,"dateInserted":"2023-06-29T17:31:17+00:00","dateUpdated":null,"dateLastComment":"2023-07-03T12:14:17+00:00","insertUserID":152316,"insertUser":{"userID":152316,"name":"Christian G.","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Christian%20G.","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/8ZFKAYNV3BAL\/n8XVTBY1DO7FK.png","dateLastActive":"2023-07-14T11:53:09+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"updateUserID":null,"lastUserID":152316,"lastUser":{"userID":152316,"name":"Christian G.","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Christian%20G.","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/8ZFKAYNV3BAL\/n8XVTBY1DO7FK.png","dateLastActive":"2023-07-14T11:53:09+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":2,"countViews":70,"score":null,"hot":3376447534,"url":"https:\/\/community.smartsheet.com\/discussion\/107096\/get-a-sheet-url-with-the-sheet-id-api","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/107096\/get-a-sheet-url-with-the-sheet-id-api","format":"Rich","tagIDs":[563],"lastPost":{"discussionID":107096,"commentID":383485,"name":"Re: Get a sheet URL with the Sheet ID [API]","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/383485#Comment_383485","dateInserted":"2023-07-03T12:14:17+00:00","insertUserID":152316,"insertUser":{"userID":152316,"name":"Christian G.","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Christian%20G.","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/8ZFKAYNV3BAL\/n8XVTBY1DO7FK.png","dateLastActive":"2023-07-14T11:53:09+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-07-03T12:14:33+00:00","dateAnswered":"2023-06-29T23:14:11+00:00","acceptedAnswers":[{"commentID":383235,"body":"
Try this: <\/p>
import smartsheet<\/p>
# Set your Smartsheet API access token<\/p>
access_token = 'YOUR_ACCESS_TOKEN'<\/p>
# Set the sheet ID for which you want to retrieve the URL<\/p>
sheet_id = 'YOUR_SHEET_ID'<\/p>
# Initialize the Smartsheet client<\/p>
client = smartsheet.Smartsheet(access_token)<\/p>
# Get the sheet details using the sheet ID<\/p>
sheet = client.Sheets.get_sheet(sheet_id)<\/p>
# Retrieve the URL from the sheet details<\/p>
sheet_url = sheet.permalink<\/p>
print(f'The URL of the sheet is: {sheet_url}')<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":563,"urlcode":"api","name":"API"}]}],"initialPaging":{"nextURL":"https:\/\/community.smartsheet.com\/api\/v2\/discussions?page=2&categoryID=320&includeChildCategories=1&type%5B0%5D=Question&excludeHiddenCategories=1&sort=-hot&limit=3&expand%5B0%5D=all&expand%5B1%5D=-body&expand%5B2%5D=insertUser&expand%5B3%5D=lastUser&status=accepted","prevURL":null,"currentPage":1,"total":204,"limit":3},"title":"Trending in API & Developers","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">