【问题标题】:shopify Unprocessable Entityshopify 无法处理的实体
【发布时间】:2012-09-25 21:21:14
【问题描述】:

在使用应用程序安装运行此代码时,我收到 Unprocessable Entity 状态代码 422 错误。 这是代码

$sc = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], $api_key, $secret);
$charge = array
(
    "webhooks"=> array
    (
        "topic"=>"orders/create",
        "address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
        "format"=>"json"
    )
);


try 
{
            $webhooks = $sc->call('POST','/admin/webhooks.json',$charge);
}
catch (ShopifyApiException $e)
{
    var_dump($e->getResponseHeaders());
}

【问题讨论】:

    标签: php shopify


    【解决方案1】:

    错误代码 422 用于验证错误。响应正文将描述错误以帮助您调试应用程序。

    例如回复可能是:{"errors":{"address":["for this topic has already been taken"]}}

    您的错误似乎是由于使用了错误的请求格式。 create 端点不采用 webhook 数组,您应该使用单数“webhook”作为顶级键。

    Webhook API 文档的请求正文格式正确。

    【讨论】:

    • $charge = '{"webhook":{"topic":"orders/create","address":"pakuniinfo.com/nomi/s.php?key=123456789","format": "json"}}';如果我发布此请求,它会给出此响应的错误“词法错误:json 文本中的无效字符。”{“webhook”:{“topic”:“orders/creat(就在这里)------^”
    • ,"format";: "json"}} "format"之后的分号
    【解决方案2】:

    将 webhook 更改为 webhook ,它可能会产生错误的请求错误

    "**webhooks**"=> array
        (
            "topic"=>"orders/create",
            "address"=>"http://www.abc123no.com/nomi/s.php?key=123456789",
            "format"=>"json"
        )
    

    【讨论】:

      猜你喜欢
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 2021-05-27
      • 1970-01-01
      相关资源
      最近更新 更多