/fetch_stock.json not getting called

Solved
Highlighted
Tourist
17 0 2

We have a pre-existing private app in our Shopify store that does some stuff, but we wanted to leverage this app to help inform Shopify of the inventory stock of items in our store.

 

We have setup a/fetch_stock.json endpoint in the private app receive a  callback for products configured to have their inventory managed by the private app. 

 

We have our callback_url set to our root url, (so we know the url Shopify should hit it root/fetch_stock.json).  

 

We have tried toggling between the different inventory managers.

 

No matter what we do, we still have not seen any callback triggered within our private app.  We have manually hit the endpoint through postman and verified that the endpoint works, and correctly logs activity when it is hit.  We reached out to our customer support contact, and they gave up and pointed us to the forums.

 

Is the /fetch_stock.json callback broken?  Or do we have something misconfigured?

 

 

 

 

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
10 3 1

Hi @gburgoon,

 

I see that you are having issues with the `/fetch_stock.json` endpoint for your private app which is a fulfillment service. There are a few things that could have gone wrong:

  1. Is your fulfillment service registered with the Shop? To find out you can fetch the following:
    https://<SHOP>.myshopify.com/admin/api/2020-01/fulfillment_services.json
    You should see your fulfillment service, e.g.:
    {
        "fulfillment_services": [
            {
                "id": some-id,
                "name": "Some Fulfillment",
                "email": null,
                "service_name": "Some Fulfillment",
                "handle": "some-fulfillment",
                "fulfillment_orders_opt_in": false,
                "include_pending_stock": false,
                "provider_id": null,
                "location_id": some-location-id,
                "callback_url": "https://myapp.com",
                "tracking_support": true,
                "inventory_management": true
            }
        ]
    }
  2.  Shopify can call your app with the following requests:
    https://myapp.com/fetch_stock.json?sku=123&shop=testshop.myshopify.com&max_retries=3&timestamp=1532548742
    http://myapp.com/fetch_tracking_numbers.json?order_names[]=#1001.1&order_names[]=#1002.1&order_names[]=#1003.2
    Make sure your app can handle these GET requests. See here for more information: https://help.shopify.com/en/api/reference/shipping-and-fulfillment/fulfillmentservice.
  3. When you create or manage a product make sure the SKU exists in your fulfillment service.

 

Please let me know if you need further help!

 

 

 

 
 
 
 
0 Likes
Highlighted
Tourist
17 0 2

Thanks for the quick response James.

 

1) The fulfillment service *is* registered with the shop

2) We've tested the /fetch_stock endpoint through browser and the endpoint returns/logs correctly, so the endpoint itself is setup correctly

3) Re: "When you create or manage a product make sure the SKU exists in your fulfillment service" -> Does this matter?  I mean, the SKU is physically there, but we can't even get the callback from fetch_stock to do a lookup for the SKU, so this doesn't seem to matter does it?

 

Is there anything else that needs to be configured?  We have followed many different pieces of documentation on fulfillment and fulfillment services, and we feel like things are configured correctly, but we still don't get any callbacks from Shopify.

 

(Another note: this endpoint is protected by the same auth process that our webhooks are protected by, so I'm assuming that Shopify has the needed information to pass auth correctly through to this callback) 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
10 3 1

Hi @gburgoon,

 

That is correct, it does not matter what you put for the SKU, as you should get a call anyways.

 

These endpoints should be unauthenticated:

/fetch_stock.json
/fetch_tracking_numbers.json

 

You can verify that the request comes from Shopify by retrieving the X-Shopify-Hmac-SHA256 header and calculate the HMAC using the shared secret provided by the API client that created the fulfillment service (in your case, the private app).

 

The verification process is similar to webhook verification (https://help.shopify.com/en/api/getting-started/webhooks#verifying-webhooks). 

def verify(data, hmac_header)
    calculated_hmac = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', SHARED_SECRET, data))
    ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, hmac_header)
  end
end

Where:

  • hmac_header is the value of the X-Shopify-Hmac-SHA256 header
  • data is the requests parameters in alphabetical order, e.g. for /fetch_stock.json "max_retries=#{max_retries}&shop=#{shop}&sku=#{sku}&timestamp=#{timestamp}"
  • verify will return true or false

Hope this answers your question.

0 Likes
Highlighted
Tourist
17 0 2

Hi @JamesWoo ,

 

Again, I very much appreciate your help.

 

I've updated the endpoint to take this approach, but unfortunately the endpoint is still not called.  I implemented it so that hmac verification isn't necessary for the endpoint to succeed (to rule out any other authentication/validation errors), but the endpoint is never called. 

 

I've retested this endpoint by calling both through postman (no hmac), and via the browser and those calls are successful.  These endpoints are meant to be GET endpoints, correct?

 

We don't have a /fetch_tracking_numbers.json endpoint as we handle this in a different manner (hopefully this isn't a requirement for the /fetch_stock.json endpoint to function).  Also, we don't have anything configured in our webhooks admin panel for these events (as the documentation doesn't say anything needs to be configured here....is this something that happens without a webhook configuration?).

0 Likes
Highlighted
Shopify Staff
Shopify Staff
10 3 1

Hi @gburgoon,

 

These endpoints are meant to be GET endpoints, correct?

Yes, both /fetch_tracking_numbers.json and /fetch_stock.json are meant to be GET endpoints.

 

 I implemented it so that hmac verification isn't necessary for the endpoint to succeed

That should be fine. HMAC verification is intended to be used to make sure the request came from Shopify and not an imposter, but should not affect the functionality of /fetch_tracking_numbers.json and /fetch_stock.json

 

That is also fine

 

Could you provide the ID of your fulfillment service? I can investigate more into possible configuration issues.

 

I set up a quick fulfillment service and these are the steps I completed:

  1. Create a private app with the write_fulfillments scope
  2. Using postman, I created the fulfillment service by POSTing to https://<SHOP>.myshopify.com/admin/api/2020-01/fulfillment_services.json with the following JSON payload:
    {
      "fulfillment_service": {
        "name": "Some Fulfillment App",
        "callback_url": "http://myapp.com",
        "inventory_management": true,
        "tracking_support": true,
        "requires_shipping_method": true,
        "format": "json"
      }
    }
    Use Basic Auth for the type of Authorization and set the Username as the API key and Password as your API key password. Note: the callback url will be called by Shopify: 
    https://myapp.com/fetch_stock.json?sku=123&shop=testshop.myshopify.com&max_retries=3&timestamp=1532548742
  3. I set up a quick rails app:
    app_controller: https://pastebin.com/FRwDmXBq
    verify: https://pastebin.com/m4ijxjLW
    routes: https://pastebin.com/bpiqZhez
  4. Create a product. In the Inventory section, select Inventory managed by <YOUR FULFILLMENT SERVICE APP> and set a SKU, save the product and you should see a request coming to your fulfillment service.

In terms of webhooks, you will want to subscribe to the fulfillments/create webhook in order to be notified about new fulfillments so that your service can make a request to "complete" the fulfillment. Your fulfillment service app will still be able to receive requests to /fetch_stock.json without setting up any webhooks.

 

 

0 Likes
Highlighted
Tourist
17 0 2

The fulfillment service ID we use is: 

 

51306070074

 

We've followed the exact steps you have below and created a new service with ID:

 

51306496058
 
We have one product pointing to the first one for inventory management, and we have a different product pointing to the 2nd one for inventory management.
 
I created a new product and pointed it to the service with ID 51306496058.
 
We still are not seeing any calls to our endpoint.
 
If we call the endpoint via the browser
 
https://ourapp.com/fetch_stock.json?sku=123&shop=testshop.myshopify.com&max_retries=3&timestamp=1532548742
We see the call succeed and we get a log on our end to verify the call occurred.
 
For some reason the endpoint still isn't called by Shopify.  Any other ideas?
0 Likes
Highlighted
Shopify Staff
Shopify Staff
10 3 1

This is an accepted solution.

Hi @gburgoon,


I checked your fulfillment service, it appears to be ok. I searched our logs for any calls to your fulfillment service and I found that it was calling:

https://yourapp.com//fetch_stock.json?max_retries=3&shop=test.myshopify.com&timestamp=1580412318

Note the trailing forward slashes after yourapp.com.

 

And Shopify received 404 not found. When I also tried to visit the above url, I also received page not found.

 

It looks like there is an issue on Shopify's side where the app is being requested with multiple slashes. In the meantime, I would try to make this work with your app.

 

I hope that helped.

0 Likes
Highlighted
Tourist
17 0 2

Yes.  Thank you @JamesWoo .  I noticed that your POST endpoint to create the service automatically appends a "/" only when the root path doesn't have one (not sure why).  If I add an additional path (ie. "yourapp.com/newpath"), the extra "/" isn't appended on creation.

1 Like