1

I am wondering if you could provide your solution on how to connect my agency's SmartsheetGov by using Smartsheet API with python. I have tried to connect to our agency's SmartsheetGov by Smartsheet API with Python. However all I got is the response of the invalid token (You could tell the message below) after revoking and creating new tokens.

I tried to follow the instruction in the link below and got my API token value (‘FwCw……’) by the steps 1 and 2.

Steps to get the API token

Result to get the API token

Then, I installed the python SDK by the Smartsheet Python SDK. The python script below was used to connect our SmartsheetGov.

import os
import smartsheet
os.environ['SMARTSHEET_ACCESS_TOKEN'] = "FwCw...."(The incomplete value of token here was for the security)
smartsheet_client = smartsheet.Smartsheet()
sheetID = 7012956985038964
sheet = smartsheet_client.Sheets.get_sheet(sheetID)
print(sheet)

However, I got the error message below:

{"response": {"statusCode": 401, "reason": "Unauthorized", "content": {"errorCode": 1002, "message": "Your Access Token is invalid.", "refId": "367b8x"}}}
{"result": {"code": 1002, "errorCode": 1002, "message": "Your Access Token is invalid.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "367b8x", "shouldRetry": false, "statusCode": 401}}
Magaren
  • 192
  • 8

1 Answers1

2
client = smartsheet.Smartsheet(api_base=smartsheet.__gov_base__)

reference: https://github.com/smartsheet-platform/smartsheet-python-sdk/blob/master/ADVANCED.md#working-with-smartsheetgovcom-accounts

Magaren
  • 192
  • 8
  • 2
    FYI, for anyone looking for info about using the Smartsheet API with Smartsheet Gov in the future, the docs cover this topic here: https://smartsheet.redoc.ly/#section/Smartsheet-Gov. There you'll find a link to instructions for how to use the API with Smartsheet Gov for the various SDKs (including, for example, the Python SDK: https://github.com/smartsheet-platform/smartsheet-python-sdk/blob/master/ADVANCED.md#working-with-smartsheetgovcom-accounts). – Kim Brandl Mar 31 '23 at 01:47
  • 1
    nice...upvoted =) – Magaren Mar 31 '23 at 02:50