Shopify Webhook

BlueConic and Shopify can be connected by configuring a Webhook connection. This document explains how.

Concept

Retrieving visitor information from Shopify is a two step process:

  • First, you will need to obtain the Shopify User ID of the visitor and store this in the profile.
  • Next, request information from Shopify using the visitor's Shopify User ID.

Retrieving the Shopify User ID

Here is how to retrieve the Shopify User ID.

  1. Create a BlueConic profile property named "Shopify User ID" with id "shopify_user_id".
  2. Obtain your Shopify API key and password.
  3. Once you have this you are going to encode it using base64. Paste the API key and the password separated by a colon (e.g. apikey:password) and click Encode. You will need the resulting base64 encoded value for the Authorization header later on.
  4. Next you need to determine your Shopify marketplace endpoint URL, e.g.: https://yourserver.myshopify.com/admin/
  5. Use this information to create a new web hook connection:
    1. Open Connections in the Navigation menu.
    2. Click Create connection.
    3. Add a Trigger a request goal.
    4. Set Request URL to https://yourserver.myshopify.com/admin/customers/search.json?limit=1&query=email:{{email}}&fields=id
    5. Request method GET
    6. Click Add request header and add a header:
      Header name Header value
      Authorization Basic [base64EncodedAPIKeyPassword]
      E.g.: Basic YXBpa2V5OnBhc3N3b3Jk
  6. With the request information complete, map the response back to the Shopify User ID profile property you created:
    1. Click Add mapping.
    2. Add the following mapping:
      JsonPath Profile property
      $.customers[0].id Shopify User ID

Retrieve other Shopify information

Now that you are collecting the Shopify User ID in the visitor's profile, you can use that in subsequent, other webhooks to retrieve information from Shopify such as total orders, total spent, last purchase date, etc.

For example, here is how to set up a goal to retrieve information via the Shopify order API:

  1. Click Add goal and add a new Trigger a request goal named "Get order information".
  2. Set Request URL to https://yourserver.myshopify.com/admin/orders.json?customer_id={{shopify_user_id}}&status=any&limit=1
  3. Set Request method to POST
  4. Click Add request header and add a header:
    Header name Header value
    Authorization Basic [base64EncodedAPIKeyPassword]
    E.g.: Basic YXBpa2V5OnBhc3N3b3Jk
  5. Add the following mappings:
    JsonPath Profile property
    $.orders[0].customer.orders_count Shopify Total Orders
    $.orders[0].customer.total_spent Shopify Total Spent
    $.orders[0].created_at Shopify Last Purchase Date

For inspiration to create additional goals to retrieve other information from Shopify, see the Shopify API reference.