joshrps / laravel-shopify-API-wrapper

Interface designed for Shopify apps created with Laravel
MIT License
93 stars 48 forks source link

Registering Webhook generates an error: 422 Unprocessable Entity #5

Closed danhanly closed 9 years ago

danhanly commented 9 years ago

This, I'm sure is something to do with the encoding of the webhook data; not being created correctly for JSON.

Following the POST details on this page, I'm getting the 422 Unprocessable Entity error.

I posted to a request bin to see what exactly was getting passed, and the following is the output:

{"webhook":{"topic":"orders\/create","address":"http:\/\/localhost\/action\/order\/1","format":"json"}}

Weird thing is, this looks correct, but Shopify keeps rejecting it.

Code to reproduce:

$webhookData = [
    'webhook' => [
        'topic' => 'orders/create',
        'address' => url('/action/order', $this->store->id),
        'format' => 'json'
    ]
];

$response = $api->call(
    [
        'METHOD' => 'POST',
        'URL' => '/admin/webhooks.json',
        'DATA' => $webhookData
    ]
);
joshrps commented 9 years ago

Hm, I've never had an issue with that, using almost identical code. Can you get the error message body? Sometimes Shopify will return errors.

From https://docs.shopify.com/api/webhook


Trying to create a webhook without an address or topic will return an error

POST /admin/webhooks.json

{
  "webhook": {
    "body": "foobar"
  }
}

Hide Response

HTTP/1.1 422 Unprocessable Entity
{
  "errors": {
    "topic": [
      "can't be blank",
      "Invalid topic specified. Topics allowed: orders\/create, orders\/delete, orders\/updated, orders\/paid, orders\/cancelled, orders\/fulfilled, orders\/partially_fulfilled, order_transactions\/create, carts\/create, carts\/update, checkouts\/create, checkouts\/update, checkouts\/delete, refunds\/create, products\/create, products\/update, products\/delete, collections\/create, collections\/update, collections\/delete, customer_groups\/create, customer_groups\/update, customer_groups\/delete, customers\/create, customers\/enable, customers\/disable, customers\/update, customers\/delete, fulfillments\/create, fulfillments\/update, shop\/update, disputes\/create, disputes\/update, app\/uninstalled"
    ],
    "address": [
      "can't be blank"
    ]
  }
}
danhanly commented 9 years ago

Managed to Dump the full error response and it was because the webhook already existed for that topic/address.

niveshsaharan commented 8 years ago

@danhanly How did you manage to dump the full output. I need it on urgent basis.

pRoy24 commented 5 years ago
orders\/create

Localhost won't work as a URL. In my case I was getting an error because I had typo in topic name I was using product/create instead of products/create