Bigcommerce API - 创建Webhooks - 无效的标题

时间:2015-01-26 21:30:57

标签: php bigcommerce webhooks guzzle

我正在为我正在研究的这个项目做一些小步骤。现在创建并注册webhook。我收到以下回复:

400 - 标题无效

我尝试过以下代码:

// Send a request to register a web hook
$http2 = new Client('https://api.bigcommerce.com', array(
    'request.options' => array(
        'exceptions' => false,
        'headers' => array(
            'X-Auth-Client' => $client_id,
            'X-Auth-Token'  => $access_token,
            'Content-Type'  => 'application/json',
            'X-Custom-Auth-Header' => $access_token,
        )
    )
));
$request = $http2->post('/'.$store_hash.'/v2/hooks', null, array(
    'scope'         => 'store/order/*',
    'destination'   => 'https://example.com/process_order.php',
    'is_active'     => true
));
$response = $request->send();
$body = $response->getBody(true);
var_dump($body);

echo '<p>Status Code: ' .  $response->getStatusCode() . '</p>';

...和

// Send a request to register a web hook
$http2 = new Client('https://api.bigcommerce.com', array(
    'request.options' => array(
        'exceptions' => false,
        'headers' => array(
            'X-Auth-Client' => $client_id,
            'X-Auth-Token'  => $access_token,
            'Content-Type'  => 'application/json',
        )
    )
));
$request = $http2->post('/'.$store_hash.'/v2/hooks', null, array(
    'scope'         => 'store/order/*',
    'headers'       => array(
        'X-Custom-Auth-Header' => $access_token,
    ),
    'destination'   => 'https://example.com/process_order.php',
    'is_active'     => true
));
$response = $request->send();
$body = $response->getBody(true);
var_dump($body);

echo '<p>Status Code: ' .  $response->getStatusCode() . '</p>';

我正在使用此处的文档: https://developer.bigcommerce.com/api/stores/v2/webhooks#create-a-hook

但是,我似乎无法解决 {secret_auth_password} 的问题?文档没有解释这一点。我也将客户端ID和客户端标题作为标题的一部分发送。

仍然将无效标题作为回复。

我正在使用Guzzle。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

经过多次尝试后,我终于找到了我做错的事。

答案:以JSON格式发送数据。

已解决的代码:

// Send a request to register a web hook
$http3 = new Client('https://api.bigcommerce.com', array(
    'request.options' => array(
        'exceptions' => false,
        'headers' => array(
            'X-Auth-Client' => $client_id,
            'X-Auth-Token'  => $access_token,
            'Content-Type'  => 'application/json',
            'Accept'        => 'application/json',
        )
    )
));
$request = $http3->post('/'.$store_hash.'/v2/hooks', null, json_encode(array(
    'scope'         => 'store/order/statusUpdated',
    'destination'   => 'https://example.com/process_order.php',
)));
$response = $request->send();