如何使用Python更新带有JSON数据的Smartsheet?

时间:2016-02-12 11:41:41

标签: python json http smartsheet-api

我使用的是smartsheet-python-sdk,我有一个简单的JSON文件,我想用它更新我的Smartsheet表。

我已成功使用python请求库删除了工作表数据,但我想知道我将如何发布数据。

以下是代码:

import requests

accessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
baseUrl = "https://api.smartsheet.com/2.0/sheets"

req = requests.get(baseUrl, verify=False, headers = {"Authorization":"Bearer %s" %accessToken})
print(req.content)

1 个答案:

答案 0 :(得分:2)

I'd suggest checking out our API documentation, specifically the Python code samples section which provides a little more information. In addition, we provide code samples for almost all of our operations in the API documentation. Simply select Python when browsing the API docs.

In reference to posting data, that would depend on which operation you'd like to use. Here's an example of a "Create Sheet" operation:

# Create sheet in "Sheets" folder.
sheet = smartsheet.models.Sheet({
    'name': 'newsheet',
    'columns': [{
            'title': 'Favorite',
            'type': 'CHECKBOX',
            'symbol': 'STAR'
        }, {
            'title': 'Primary Column',
            'primary': True,
            'type': 'TEXT_NUMBER'
        }, {
            'title': 'Status',
            'type': 'PICKLIST',
            'options': [
                'Not Started',
                'Started',
                'Completed'
            ]
        }
    ]
})
action = smartsheet.Home.create_sheet(sheet)
sheet = action.result

You can find similar examples for other operations. If you have additional questions, you can always reach out to our API support team: api@smartsheet.com