Smartsheet webhook子镜

2024-06-10 08:30:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使用以下代码在python中的一个工作表中创建一个webhook,其中包含特定列的子范围:

my_webhook = smartsheet_client.Webhooks.create_webhook(
    smartsheet.models.Webhook({
        'name': 'test 10',
        'callbackUrl': 'https://my_web.com/webhook/test10',
        'scope': 'sheet',
        'scopeObjectId': 0000000000000000,
        'subscope': {'columnIds': [0000000000000000]},
        'events': ['*.*'],
        'version': 1
        }))

当我获得成功创建的webhook及其ID时,响应中缺少子范围。 有人知道我做错了什么吗


Tags: 代码namehttpstestclientwebmodelsmy
2条回答

您的代码实际上与我的完全相同,子范围也不适用于我。我从smartsheet python sdk pip包2.86升级到2.105,现在我的webhook设置正确了。我还验证了子范围设置是否有效,这大大减少了我必须处理的事件数量

这是我的代码(尽管它与您的基本相同)

def createSheetWebhook(name, sheet_id, target, subscope=[]):
    new_webhook = smartsheet_client.Webhooks.create_webhook(
        smartsheet.models.Webhook({
            "name": F"sheet changes for {name}",
            "callbackUrl": target,
            "scope": 'sheet',
            "scopeObjectId": sheet_id,
            "subscope": {
                "columnIds": subscope
            },
            "events": ['*.*'],
            "version": 1
        })
    )
    return new_webhook.result.id

我对Smartsheet Python SDK不是很熟悉,但总的来说,每当我对如何使用SDK实现特定操作有疑问时,我都会发现在SDK的GitHub repo中查看集成测试代码是很有帮助的。在本例中,SDK repo中的integration test for webhooks显示了以下用于创建webhook的代码:

def test_create_webhook(self, smart_setup):
        smart = smart_setup['smart']

        webhook = smart.models.Webhook()
        webhook.name = 'My Webhook'
        webhook.callback_url = 'https://www.smartsheet.com'
        webhook.scope = 'sheet'
        webhook.scope_object_id = smart_setup['sheet'].id
        webhook.events.append('*.*')
        webhook.version = 1
        webhook.subscope = smart.models.WebhookSubscope({'column_ids': [smart_setup['sheet'].columns[0].id]})

        action = smart.Webhooks.create_webhook(webhook)
        assert action.message == 'SUCCESS'
        assert isinstance(action.result, smart.models.Webhook)
        TestWebhooks.webhook = action.result

请特别注意subscope属性的设置方式与上面发布的不同。我建议尝试在这段代码之后对您的代码进行更多的建模,看看您是否能够达到预期的结果

相关问题 更多 >