When orders from Shopify come over into Infoplus, the order's tags from Shopify are turned into order tags in Infoplus.  However, if there are customer level tags in Shopify, those do not automatically come over into Infoplus.  To accomplish this, we have an example script below that runs against orders and does the following:


  1. Pulls the Shopify customer ID out of the extra order data in Infoplus then uses it, along with a Shopify access token, to make an HTTP request to the Shopify API.
  2. Converts the response from Shopify from string to JSON format, then parses out the customer tags from the response.  
  3. Loops through the customer tags, adding each of them as tags to the order in Infoplus. 


Due to the ever-changing nature of writing and maintaining scripts, Infoplus does not provide support in this area. We recommend someone in your IT Department handles scripting requests internally so that you keep all control over the process.

Some further notes about this script:

  • The script should be created with a Script Type of Record and and Record Type of Order.
  • This script should only be ran against orders that came from Shopify. Use a smart filter and trigger to automatically run the script against orders that came from Shopify.
  • Replace "YOUR-SHOPIFY-ACCESS-TOKEN" with a valid API access token from Shopify.  Please contact Infoplus support if you're not sure what your access token is.
  • Replace "YOUR-SHOPIFY-SUBDOMAIN" with the proper subdomain from your Shopify site.  For example, if your shopify site is at https://acmeproducts.myshopify.com, you would use the value "acmeproducts";
// Set variables needed for the http request to the Shopify API
var apiKey = "YOUR-SHOPIFY-ACCESS-TOKEN";
var shopifySubdomain = "YOUR-SHOPIFY-SUBDOMAIN";
var customerId = getOrderExtraData(order, "SHOP-CUSTOMER.ID");
utils.log("Customer Id: " + customerId);

if(!customerId)
{
   utils.log("Did not find a shopify customer id on this order - exiting.");
   return;
}

// Make the API request to the Shopify customer endpoint
var httpResponse = utils.httpRequest({
   "method": "GET",
   "headers": ["X-Shopify-Access-Token: " + apiKey],
   "url": "https://" + shopifySubdomain + ".myshopify.com/admin/customers/" + customerId + ".json"
});

// Log if the API request is working
// utils.log("Status: " + httpResponse.statusCode);
// utils.log(httpResponse.body);

// convert http response body from string to JSON
var shopifyCustomer = utils.stringToJson(httpResponse.body);
utils.log(shopifyCustomer);

// parse tags out of the JSON
var customerTagList = shopifyCustomer.get("customer").get("tags");
utils.log(customerTagList);

// convert customerTagList to an array so we can loop over it
var customerTagArray = customerTagList.split(',');


// loop through the list of customer tags, then add each on as tag on the order in Infoplus
if(customerTagArray != null)
{
  for(var i=0; i<customerTagArray.length; i++)
  {
    var customerTag = customerTagArray[i];
    infoplusApi.addTag("order", order.orderNo, customerTag);
  }
}



function getOrderExtraData(order, code)
{
   var extraDataList = order.extraOrderData;
   if(extraDataList != null)
   {
      for(var i=0; i<extraDataList.size(); i++)
      {
         var extraData = extraDataList.get(i);

         if(extraData.code == code)
         {
            return(extraData.value);
         }
      }
   }
   return(null);
}