I’m working on a Shopify app integration. Each user account in my app has a unique subdomain. I need to set up OAuth to redirect to different subdomains for each connection request. But I’m running into issues.
When I try to redirect to the Shopify authorize URL, I get this error:
{"error":"invalid_request",
"error_description":"The redirect_uri and application url must have matching hosts"}
My URL looks like this:
https://STORE.myshopify.com/admin/oauth/authorize?client_id=MY_ID&scope=read_order&redirect_uri=USER.MYAPP.com
I’ve tried setting the app URL in Shopify to things like http://MYAPP.com
or http://*.MYAPP.com
, but no luck.
It only works if I set it to the exact subdomain: http://USER.MYAPP.com
I could use a middleman endpoint as a workaround, but I’d rather have Shopify support subdomains directly.
Anyone know how to make this work? Am I missing something obvious?
Here’s a simplified version of my code:
import requests
def get_auth_url(shop_name, callback_url):
consumer_key = '1234abcd'
return f'https://{shop_name}.myshopify.com/admin/oauth/authorize?client_id={consumer_key}&scope=read_orders&redirect_uri={callback_url}'
def get_access_token(shop_name, code):
consumer_key = '1234abcd'
consumer_secret = 'secretstuff'
url = f'https://{shop_name}.myshopify.com/admin/oauth/access_token'
data = {
'client_id': consumer_key,
'client_secret': consumer_secret,
'code': code
}
response = requests.post(url, json=data)
return response.json()['access_token']
def get_products(shop_name, token, page=1):
url = f'https://{shop_name}.myshopify.com/admin/products.json'
headers = {'X-Shopify-Access-Token': token}
params = {'page': page, 'limit': 250}
response = requests.get(url, headers=headers, params=params)
return response.json()
The callback URL I’m trying to use is something like http://user1.myapp.com/shopify/callback
. Any ideas on how to make this work with Shopify’s API?