【问题标题】:http request using json-pointer slack view.publish JSON-encoded string使用 json-pointer slack view.publish JSON 编码字符串的 http 请求
【发布时间】:2021-07-21 01:01:10
【问题描述】:

我正在尝试将此 api POST 请求发送到 slack api 上的 view.publish 端点

正如文档所解释的,我在参数中使用令牌和 user_id,但我不知道我需要对视图参数做什么

我在标题中将“application/json;charset=UTF-8”设置为内容类型,并在正文中设置我要发布的有效负载的 JSON:

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "This is a section block with a button."
            },
            "accessory": {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "text": "Click Me",
                    "emoji": true
                },
                "value": "click_me_123",
                "url": "http://scoreboard-azureslackbot-salvosoftware.s3-website.us-east-2.amazonaws.com/",
                "action_id": "button-action"
            }
        }
    ]
}

当我进行 api 调用时显示此错误:

{
    "ok": false,
    "error": "invalid_arguments",
    "response_metadata": {
        "messages": [
            "[ERROR] failed to match all allowed schemas [json-pointer:/view]",
            "[ERROR] must provide an object [json-pointer:/view]",
            "[ERROR] must provide an object [json-pointer:/view]"
        ]
    }
}

文档说视图必须是 JSON 编码的字符串

此警告也会显示在正文选项卡中:

【问题讨论】:

  • 去掉你手动添加的内容hehader,postman自动添加

标签: api http postman


【解决方案1】:

此答案来自 Aubrey,支持团队处于松弛状态。

不需要参数。 在“授权”选项卡中,您需要获得授权。

在正文上,您需要设置为原始 -> JSON,这将是您的 JSON:

{
    "user_id": {{YOUR_USER_ID}},
    "view": {
        "type": "home",
    "blocks": [
        {
            {{YOUR_PAYLOAD}}
        }
    ] 
    }
}

它基于这个 CURL 命令帮助了我

curl -L -X POST 'https://slack.com/api/views.publish' \
-H 'Content-type: application/json' \
-H 'Authorization: Bearer {{YOUR TOKEN}}' \
--data-raw '{
    "user_id": {{YOUR USER ID}},
    "view": {
        "type": "home",
    "blocks": [{
            {{YOUR PAYLOAD}}
        }] 
    }
}'

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多