-1

so ill try to keep this short as possible. I am a newbie to the SmartSheet Python SDK and im trying to call all the data from the Smartsheet and hopefully use that as a starting point for myself. So far what I have

import smartsheet

smartsheet = smartsheet.Smartsheet('token1')

Which I am running/compile on Python Shell, and so far with those two lines I am running it and not getting an issue, when I try to implement anything else to pull the data, I keep getting errors.

on topic but a separate thing

I also have this line of code to pull specific line from the SmartSheet,

action = smartsheet.Sheets.get_sheet(SheetID, column_ids=COL_ID, row_numbers="2,4")

My question regarding this is, where do I find the Column ID, I know how to access the Sheet ID, but I cant access or find the Column ID on smartsheets, I dont know if i am overlooking it. Just looking to get off in the right direction, being the newbie I am, any help appreciated.

EDIT

5183127460046724
Task Name

2931327646361476
Duration

7434927273731972
Start

EDIT 2

Task Name
task1 text here


Duration
duration1 text here

Start
start1 example here
RickRollNGo
  • 3
  • 1
  • 4
  • "when I try to implement anything else to pull the data, I keep getting errors." -- can you please update your post with specifics about this? i.e., specifically what line of code is resulting in an error, and specifically what error are you receiving? Re how to get Column ID, you can execute a "Get Columns" operation (for a specific sheet) via the API, and the result of that operation will contain the collection of columns in that sheet (each one having an id attribute). (The "Get Sheet" operation would also give you this info -- but is overkill if all you're interested in is Columns.) – Kim Brandl Jul 28 '16 at 22:24
  • When I try to implement any lines of code which I think will get my program to retrieve the information, is what I mean, nothing in specific, but in general. I have tried many things and dont know if I am going in the right direction. Need guidance on pulling ALL information, so that I can start learning how to knit-pick any data that I want in particular – RickRollNGo Aug 02 '16 at 18:07
  • I'd suggest you spend some time reviewing the Smartsheet API Documentation: http://smartsheet-platform.github.io/api-docs/#python-sample-code. Topics in the "API Reference" section contain Python sample code for each operation. For example, to find Column ID for a specific column in the Sheet, you'd use the "Get All Columns" operation (sample code here >> http://smartsheet-platform.github.io/api-docs/?python#get-all-columns) and then examine the results to identify the ID of the column you're interested in. – Kim Brandl Aug 03 '16 at 23:10
  • Thanks Kim, So i am using these example code and running it and yet I still am getting an error. I am using this: – RickRollNGo Aug 08 '16 at 17:19
  • Thanks, So i am using the sample and running it with my credentials and yet I still am getting an error import smartsheet smartsheet = smartsheet.Smartsheet('token1') # all columns. action = smartsheet.Sheets.get_columns(2596170863273860, include_all=True) columns = action.data action = smartsheet.Sheets.get_columns(sheetId) pages = action.total_pages columns = action.data and getting this Traceback (most recent call last): File "C:\Users\jxm10\Desktop\python1.py", line 9, in columns = action.data AttributeError: 'Error' object has no attribute 'data' – RickRollNGo Aug 08 '16 at 17:26
  • Sorry that I couldnt format the one above, I literally ran out of characters. This is the error I am seeing ***'Traceback (most recent call last): File "C:\Users\jxm10\Desktop\python1.py", line 9, in columns = action.data AttributeError: 'Error' object has no attribute 'data'*** ' – RickRollNGo Aug 08 '16 at 17:28
  • Please see my answer below (and, if it works for you, please mark it as an 'accepted' answer so that others may benefit from it in the future). Also, for future reference -- you should *edit* your original post to add code samples, etc., instead of trying to add them to a 'comment' (since, as you've experienced, Comments do not allow you to format code and are fairly limited in terms of max length). – Kim Brandl Aug 08 '16 at 19:30

1 Answers1

3

The following sample code retrieves a list of all columns from the specified Sheet, and then iterates through the columns printing out the Id and Title of each column. (You'll obviously need to replace ACCESS_TOKEN and SHEET_ID with your own values.)

# Import.
import smartsheet

# Instantiate smartsheet and specify access token value.
smartsheet = smartsheet.Smartsheet('ACCESS_TOKEN')

# Get all columns.
action = smartsheet.Sheets.get_columns(SHEET_ID, include_all=True)
columns = action.data

# For each column, print Id and Title.
for col in columns:
    print(col.id)
    print(col.title)
    print('')

UPDATE #1

Here's some sample code that shows how to access property values within a Get Sheet response.

# Get Sheet - but restrict results to just 2 rows (#2, #4) and a single column/cell (Id = COLUMN_ID)
action = smartsheet.Sheets.get_sheet(SHEET_ID, column_ids=COLUMN_ID, row_numbers="2,4") 

# print info from row #2 (the first row in the "Get Sheet" response) for the single specified column (cell)
print('Row #: ' + str(action.rows[0].row_number))
print('Row ID: ' + str(action.rows[0].id))
print('Column ID: ' + str(action.columns[0].id))
print('Column Title: ' + action.columns[0].title)
print('Cell (display) value: ' + action.rows[0].cells[0].display_value)
print('')

# print info from row #4 (the second row in the "Get Sheet" response) for the single specified column (cell)
print('Row #: ' + str(action.rows[1].row_number))
print('Row ID: ' + str(action.rows[1].id))
print('Column ID: ' + str(action.columns[0].id))
print('Column Title: ' + action.columns[0].title)
print('Cell (display) value: ' + action.rows[1].cells[0].display_value)
print('')
Kim Brandl
  • 13,125
  • 2
  • 16
  • 21
  • Thanks Kim! One question though, when I use the last bit of code for the columns, its printing out the results such like: 5183127460046724 Task Name 2931327646361476 Duration 7434927273731972 Start I was reading through the documentation and I dont know If I missed where it mentions printing out the Texts in each columns. not exactly sure where it gets those numbers above, or what they mean. P.s. I made the edit on the original post so you could see it better – RickRollNGo Aug 09 '16 at 15:33
  • The number is the column ID, the words that follow each number represent the Title of that column. This operation ("List All Columns) returns information about the columns in a Sheet -- it won't return data that resides in the sheet's cells. To get that, you'll need to use the "Get Sheet" operation. – Kim Brandl Aug 09 '16 at 15:42
  • HI Kim, thanks, I did that and It seems as though It brings what is one the sheet and much more for example, ***{"format": null, "displayValue": null, "linksOutToCells":*** It looks to be in JSON format. is there a operation which allows me to print it out exactly how it is on smartsheets without converting it to JSON? – RickRollNGo Aug 09 '16 at 19:51
  • or to give you a visual, for example how I have it on the second edit in the original post – RickRollNGo Aug 09 '16 at 20:32
  • Or at least what im getting anything similar to what they have on the sample output for the sample code – RickRollNGo Aug 09 '16 at 20:50
  • Added "Update #1" which contains sample code showing the **Get Sheet** call and examples of how to access data in that response (including cell value for specified row(s)). – Kim Brandl Aug 09 '16 at 23:54