TuffRivers's avatar

Registering a WebHook

Hi All,

I am using an ecommerce platform that allows you to register a webhook to receive notifications when certain events happen on the site. How do i actually trigger this post request to register the webhook if i have no UI for it in Laravel or nothing to trigger it? Do i just put it in a script file and run it CLI php webhook.php ?

This is my post request:

$clientSecret = "my_secret";
$request = new HttpRequest();
$request->setUrl('WebHookUrl');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'Cache-Control' => 'no-cache',
  'X-Auth-Token' => 'ClientToken',
  'X-Auth-Client' => 'ClientAuth',
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
));

$request->setBody('{
    "scope": "store/order/*",
    "headers": {
      "X-Custom-Auth-Header": "$clientSecret"
    },
    "destination": "url_endpoint",
    "is_active": true
  }');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
0 likes
3 replies
NickVahalik's avatar

Hrm. This looks like BigCommerce. ;)

In order to a register a webhook, you've got to set your app up to be an Oauth2 client and then authenticate with the app. Once your app has been authorized, you'll then POST to the hooks resource per the API documentation on their resource page.

If you're not using BigCommerce, the flow above is likely still valid. You'll just need to read the API documentation and figure out what they want. There is usually a set of APIs to register/list/delete webhooks.

TuffRivers's avatar

Hi,

It is bigcommerce.

Ive hit the api before with testing (the v3) with authentication.

But in curious how do i actually trigger the post without UI? Do i just use the command line ?

NickVahalik's avatar

Yes, @TuffRivers . You'd just use the token you've been giving via Oauth and you can do a POST to the web service using something like cURL.

Please or to participate in this conversation.