Shopify / shopify-app-template-node

MIT License
890 stars 402 forks source link

How to receive webhooks from 3rd party #1277

Open nboliver-ventureweb opened 1 year ago

nboliver-ventureweb commented 1 year ago

How can I receive a webhook from an external service and, assuming they have been validated, use their payload to interact with the admin API?

I have set up a new route that doesn't use the /api path and have that working, but I'm not sure how to then forward a request on to an authenticated /api route from within the Express back end.

I tried using http-proxy-middleware and also tried creating a custom app session:

    const session = await shopify.api.session.customAppSession(
      'external-service-test.myshopify.com'
    );
    data = await shopify.api.rest.Product.count({
      session,
    });

With the later, I get "error": "Missing access token when creating REST client".

Any help appreciated!

As an aside, I've spent a good amount of time scouring the docs to try and figure this out, but find the documentation for interacting with the API really confusing to follow and spread out across so many different repos and doc pages that don't provide quite enough info to easily get the whole picture. For example: https://github.com/Shopify/shopify-api-js/blob/main/docs/guides/session-storage.md#load-a-session-from-storage: in the code block there it says // getSessionFromStorage() must be provided by application but there are no examples of what that does or how to set it up.

sixkin-stephens commented 10 months ago

Bump. I'm also trying to figure out how to do this.