Order of columns and Row-Cells in response to API Get Sheet request
Hello.
In general, I understand that Smartsheet has made it clear that no order of properties or even any order of array entities may be assumed or inferred to any response to any API request. And fair enough.
My question is about the response to a single invocation of the API GET SHEET - GET https://api.smartsheet.com/2.0/sheets/{sheetId} .
In the `columns` property, we get back an array of columns.
In the `rows` property, we get back an array of rows, and each row has within it an array of `cells`, one for each column.
Can we assume and be guaranteed that the array of cells in each row will be the same size and of the same order? (Seems likely, but documentation appears to be silent on this point).
If the answer to that is "YES", can we further assume and be guaranteed that the array of columns will be the same size and in the same order as the array of cells in each of the rows?
And if this is true, can the documentation by updated to reflect this truth?
Best Answer
-
Hi @sgolux
The answer to this and your other post is the same so I'll duplicate my response in both threads:
No, there isn't a guarantee for the order of any lists returned from the API. While it may sometimes return in the proper order, this cannot (and should not) be relied upon.
The only way to handle the response is mapping by column ID. To make it easier to program, you can look at the columns array and make a mapping of column ID to column title - then you can refer to that mapping with the human readable title and tease out the ID.
A best practice method is in this example: https://github.com/smartsheet-samples/python-read-write-sheet/blob/master/python-read-write-sheet.py#L13
Cheers,
Genevieve
Need more help? 👀 | Help and Learning Center
こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 | Global Discussions
Answers
-
Hi @sgolux
The answer to this and your other post is the same so I'll duplicate my response in both threads:
No, there isn't a guarantee for the order of any lists returned from the API. While it may sometimes return in the proper order, this cannot (and should not) be relied upon.
The only way to handle the response is mapping by column ID. To make it easier to program, you can look at the columns array and make a mapping of column ID to column title - then you can refer to that mapping with the human readable title and tease out the ID.
A best practice method is in this example: https://github.com/smartsheet-samples/python-read-write-sheet/blob/master/python-read-write-sheet.py#L13
Cheers,
Genevieve
Need more help? 👀 | Help and Learning Center
こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 | Global Discussions
-
Thanks! This is disappointing because it will require (if not making assumptions about order) that every single row on the sheet have all of its cells iterated through to find this mapping definitely, rather than just being able to do one iteration on the response to the API invocation, and use that same integration to map every row.
I hope you can turn this into an enhancement request!
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 63.5K Get Help
- 402 Global Discussions
- 213 Industry Talk
- 450 Announcements
- 4.7K Ideas & Feature Requests
- 141 Brandfolder
- 135 Just for fun
- 56 Community Job Board
- 454 Show & Tell
- 31 Member Spotlight
- 1 SmartStories
- 296 Events
- 36 Webinars
- 7.3K Forum Archives