AWS EventBridge set up

Solved
dstefani
Tourist
4 0 0

Hello, totally new to Shopify...

I've been tasked with doing the following: Set up a Shopify app using AWS Event Bridge.

The goal is, at the time an order is placed on Shopify the app sends the order information to an AWS SQS queue.

I've created a development store and a new custom app. I followed the instructions in this tutorial >>

I'm stuck at the webhook part. If I'm not calling the API from an outside app, just sending it to SQS, what more is there for me to do?

Also, I tried to install the app in my store using the "merchant install link", but when I go to mystore > apps, the app doesn't show up as being installed.

I found this post about the solution to that problem, but I don't know where to get the values I'd need for the OAuth URL other than api-key, mystore and scope.

 

Is there a better step by step tutorial for this?

 

Thanks - Don

0 Likes
mikedasilva
Shopify Staff
Shopify Staff
26 2 2

Hi,

That EventBridge tutorial is the best place to get started with setting it up. Basically, you have to have a custom or public app to set up your Partner Event Sources. Once that's all been set up, you need to use the token generated from your app to call the Shopify Webhooks API to subscribe to webhook topics that you'd like to receive events for. Here are some other helpful links:

https://shopify.dev/concepts/about-apis/authentication

https://shopify.dev/docs/admin-api/graphql/getting-started#using-your-access-token

https://shopify.dev/docs/admin-api/graphql/reference/mutation/webhooksubscriptioncreate?api[version]...

https://shopify.dev/tutorials/manage-webhook-events-with-eventbridge#subscribing-with-graphql

Hope this helps!

Mike

mikedasilva | Developer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
dstefani
Tourist
4 0 0

Hello, thanks for your response.

But actually, I'm more confused than when I posted the OP.

I've followed all the steps in the EventBridge tutorial, but there are parts that are missing from it and I've been guessing about what's missing - reading a bunch of different docs and trying to figure out how the answers relate to using a custom app with EventBridge. These are some the things I'm still confused about:

  1. In App setup, redirect and whitelist URLs. From what I've read, they need to point another custom built app on a server, like in this tutorial: https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react. But I don't see how that relates if I'm use EventBridge that points to SQS?
  2. Installing the App in my store using the Merchant Install link. I guess I can't do this until I have the proper redirect and whitelist URL's. I've read posts here saying that it doesn't work.
  3. Subscribing to a webhook by using the Subscribe with the REST API method. I was thinking that this would be the best way for me to do this, but I'm not sure if this is the correct way for EventBridge. The sample code in the tutorial doesn't mention OAuth, I've read your docs about it but I'm still trying to see where that fits with the sample URL given in the tutorial. I tested using the API with a URL like this: GET https://{APIKey}:{secretKey}@mystore.myshopify.com/admin/api/2020-07/orders.json. I got my keys from creating a Private App in my store admin. This worked so I tried the same format in Postman with a POST, using the body from the sample in the tutorial and sending it to *webhooks.json. I got a 200 response and a link to log in to my store.

I've spent a good amount of time trying to figure this out, I would really be grateful for any help to get this to work.

 

Thank you - Don

0 Likes
ft3
Tourist
9 1 3

This is an accepted solution.

Hi Don,

It took me a half a day to get EventBridge working for my application. I hope this helps.

The existing tutorial shows how to set up webhooks using the `@shopify/koa-shopify-webhooks` package. However, the library currently doesn't support register webhooks via the EventBridge integration. If you check out the source code, you will find that that only the `webhookSubscriptionCreate` mutation is supported. You can make slight modifications locally to use the `eventBridgeWebhookSubscriptionCreate` mutation. It would look something like:

 

const { Method, Header } = require("@shopify/network")

module.exports.registerWebhook = async function registerWebhook({
  address,
  topic,
  accessToken,
  shop,
  apiVersion
}) {
  const response = await fetch(
    `https://${shop}/admin/api/${apiVersion}/graphql.json`,
    {
      method: Method.Post,
      body: buildQuery(topic, address),
      headers: {
        "X-Shopify-Access-Token": accessToken,
        [Header.ContentType]: "application/graphql"
      }
    }
  )

  const result = await response.json()

  if (
    result.data &&
    result.data.eventBridgeWebhookSubscriptionCreate &&
    result.data.eventBridgeWebhookSubscriptionCreate.webhookSubscription
  ) {
    return { success: true, result }
  } else {
    return { success: false, result }
  }
}

const buildQuery = (topic, arn) => {
  return `
    mutation {
      eventBridgeWebhookSubscriptionCreate(
        topic: ${topic},
        webhookSubscription: { 
          arn: "${arn}"
          format: JSON 
        }
      ) {
        webhookSubscription {
          id
        }
        userErrors {
          message
        }
      }
    }  
  `
}

 

Using your custom registerWebhook function, the rest of the tutorials should fall into place.

await registerWebhook({
  accessToken,
  address: "<arn address>",
  apiVersion: ApiVersion.July20,
  shop,
  topic: "PRODUCTS_CREATE"
})

 

Assuming you have already successfully set you your EventBridge source and target, you should be good to go.

I haven't circled back to clean up the register function -- my hope is that the quilt project will eventually include support for EventBridge. At any rate, I hope this was helpful.

ft3
Tourist
9 1 3

FYI -- `@shopify/koa-shopify-webhooks` now supports EventBridge.

https://github.com/Shopify/quilt/pull/1594

0 Likes
mikedasilva
Shopify Staff
Shopify Staff
26 2 2

@ft3 you beat me to it! Yes, we just added support for EventBridge. Hope that helps with development!

 

Cheers,

Mike

mikedasilva | Developer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
ft3
Tourist
9 1 3

@mikedasilva GitHub notifications ¯\_(ツ)_/¯. I appreciate it - thank you.

Forest

0 Likes