Uniquely identify a merchant (shop)?

I’m looking for an unambiguous, permanent way to uniquely identify a merchant using my app. For example, in my hosting environment add such a unique identification to database keys.

I have read that using the “xxx.myshopify.com” domain fits this purpose - I’m looking to confirm that or learn of a better way.

I do this GraphQL query for a merchant:

query shop {
  shop {
    name
    domains {
      host
      id
      url
    }
    url
    id
  }
}

and see a result of

{
  "data": {
    "shop": {
      "name": "Cool Company",
      "domains": [
        {
          "host": "cool-company-co.myshopify.com",
          "id": "gid://shopify/Domain/85799333767",
          "url": "https://cool-company-co.myshopify.com"
        },
        {
          "host": "www.coolcompany.com",
          "id": "gid://shopify/Domain/86271236143",
          "url": "https://www.coolcompany.com"
        },
        {
          "host": "coolcompany.com",
          "id": "gid://shopify/Domain/86279321911",
          "url": "https://coolcompany.com"
        }
      ],
      "url": "https://www.coolcompany.com",
      "id": "gid://shopify/Shop/58093905679"
    }
  },

So… is the accepted method to iterate through the domains and pick the one that ends in “myshopify.com” and use that forever as the unique ID?

Or is there a simpler way to just get a unique, permanent ID?

Also, in the query result above what is the last ID shown (58093905679)? It seems to be at the shop level and is different than the other domains. Is this a candidate for a unique, permanent ID?

Thanks for any guidance.

You should be able to pull the shop ID but grabbing the permanent domain .myshopify.com would likely be ideal because you could quickly visit it if necessary.

1 Like

I have read that using the “xxx.myshopify.com” domain fits this purpose - I’m looking to confirm that or learn of a better way.

Yes. You can safely use xxx.myshopify.com as a unique ID. Moreover, if you are querying the shop object from Shopify. It’s safe to assume that id will always be unique.

So… is the accepted method to iterate through the domains and pick the one that ends in “myshopify.com”?

No, you can actually query the myshopifyDomain on the shop object. It will give you the xxx.myshopify.com as a string and it can be used as a unique id forever.

Attaching a link to the field.

3 Likes

Correct. A store might have multiple domains that may end in myshopify.com, a store can request to get a new myshopify domain. But the query Prakhar suggested myshopifyDomain will return the permanent domain that you’ll want to store, as that is immutable and will always identify the store.

2 Likes

Good info and clear answer - thanks!