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
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:
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.