pythonsdksmartsheet-api

Why am I seeing an 'AttributeError' when using the Python Smartsheet SDK to create a new sheet in a folder?


I'm trying to use the Python SDK and API to create a new sheet in Smartsheet and was successful in installing the SDK via pip install smartsheet-python-sdk in my terminal. However, when I try to create a new sheet in a folder via the create_sheet_in_folder under the Folder object I'm not able to as that method is not showing up in my IDE, but I have folders.py saved on my device. I've verified my API key works by adding columns into a sheet but for some reason it looks like I can't really do much with creating a new sheet.

Here's my code for reference:

#Smartsheet API Challenge
import smartsheet

# Set your Smartsheet API access token
access_token = "ACCESS_TOKEN"
smartsheet_client = smartsheet.Smartsheet(access_token=access_token)

folder_id = "FOLDER_ID"
# Create a new sheet
sheet_spec = smartsheet.Smartsheet.models.Sheet({
'name' : 'Sheet B',
'columns' : [{
'title' : 'Primary Column',
'primary' : True,
'type' : 'TEXT'
}, {
'title' : 'Col 1',
'type' : 'TEXT'
}
]
})

#make the new sheet
response = smartsheet_client.models.Folder.create_sheet_in_folder(folder_id,sheet_spec)
new_sheet = response.result

Here's the error I get:

response = smartsheet_client.models.Folder.create_sheet_in_folder(folder_id,sheet_spec)

AttributeError: type object 'Folder' has no attribute 'create_sheet_in_folder'

Solution

  • There are two issues with the code you posted.

    First, the line that calls the create_sheet_in_folder method should be:

    response = smartsheet_client.Folders.create_sheet_in_folder(folder_id,sheet_spec)

    And second, the type attribute value for each column should be set to TEXT_NUMBER (not TEXT):

    'type' : 'TEXT_NUMBER'

    Make these changes and your code should successfully create the new sheet in the specified folder.