Productivity

How to Extract the Shopify URL from a Website in HubSpot

If you're working at a Shopify app selling to Shopify brands, you might be wondering how to extract the shop's unique Shopify URL out of their domain.
script to get shopify url from a website
Written by
Swivel Team
Published on
April 4, 2024

Let's face it. A clean CRM is the reason you sleep well at night. This guide will walk you through how to easily get a shop's unique Shopify URL from their website domain. While this specific post is focused on HubSpot, the basic steps are the same no matter what CRM you use.

Just before we dive in, note that if a shop is using Shopify as a backend service or is completely headless, this script may not work. 

Step 1: Build a HubSpot workflow

Your workflow should be triggered when the Website field is known, but the Shopify URL field is unknown.

Step 2: Python

Using a code step, pass the website property into the code

pass website field to workflow
Passing the website field is a MUST!

Step 3: Paste and Run the Following Code

import requests

def main(event):

   shopify_url = None

   website = event.get("inputFields").get("website")

   if "https://" not in website:

       store_url = requests.get("https://" + website + "/admin").url

   else:

       store_url = requests.get(website + "/admin").url

   print(store_url)

   if "myshopify" in store_url:

       shopify_url = store_url.split("/admin")[0].split("https://")[1]

       print(shopify_url)

       return {"outputFields": {"shopify_url": shopify_url}}

   else:

       return {"outputFields": {"shopify_url": None}}

This will return a Shopify URL (if found). 

Step 4: Copy Shopify URL to Your Field

If the URL is found, you can now use an if/else branch on the code step’s value to pass the Shopify URL into its own field.

And that’s it! Super simple. Here’s the final workflow: 

the hubspot workflow
The final workflow in HubSpot

While you’re here, feel free to check out Swivel, the spin-to-win app for Slack that helps teams boost morale, recognize each other, and have fun.

Let's keep in touch.
No spam. Just the latest releases and tips, interesting articles, and exclusive interviews in your inbox every week.
Sweet! Keep an eye on your inbox for our next post in the Swivel Spin.
Oops! Something went wrong while submitting the form. Drop us a line at support@playswivel.com.