Trying to access admin API as private app using Python

AI-generated summary

Accessing the Shopify Admin API as a private app in Python; confusion over where to get a “password” and a request for a working example.

Clarification:

  • For private apps, the “password” referenced in older docs is the private app access token.
  • Official examples were provided via the shopify_python_api getting-started guide.

Outcome (working approach shared):

  • Authenticate by creating a session: shop_url = “{shop}.myshopify.com”, api_version set, and access token used in shopify.Session(…). Then call ShopifyResource.activate_session(…).
  • Data retrieval confirmed by fetching a product via Product.find({product_id}).

Key details:

  • Use the private app access token in place of “password.”
  • api_version noted as ‘2023-04’ at the time; ‘2023-10’ was not recognized yet.
  • The older pattern embedding API_KEY:PASSWORD in the base URL was superseded by using Session with the access token.

Status: Resolved. The user successfully authenticated and retrieved product data; no open questions remain.

I am new to the Shopify API and am trying to access my store information for the first time. I am building an app to synchronize my inventory between Shopify and my Lightspeed store. The built-in integration does not meet my needs. Getting anything successfully returned from an API the first time is always the biggest hurdle. From the documentation, I should be able to create a password for a private app but I only see a secret key, API key and access token. Is there somewhere to create a password?

From Shopify Open Source > shopify_python_api

"For a private App you just need to set the base site url as follows:

python
shop_url = "https://%s:%s@SHOP_NAME.myshopify.com/admin" % (API_KEY, PASSWORD)
shopify.ShopifyResource.set_site(shop_url)

That’s it you’re done, skip to step 6 and start using the API! "

Also, is there an example of a fully coded Python request to get information on a specific product? The snippets don’t seem to get past authorization. Once I can actually get data back from the API, I should be good to go. Thanks!

Hey @SSmythOV

The password is the access token. Here’s some example code: https://github.com/Shopify/shopify_python_api#getting-started

Got this to return results! I am off and running. The exact syntax I used is below, replacing bracketed info with my details:

private_app_password = “{access token}”
shop_url = “{my shop name}.myshopify.com”
api_version = ‘2023-04’ #Note that as of now, the API does not recognize ‘2023-10’ yet. This is the highest api version that was recognized.
session = shopify.Session(shop_url, api_version, private_app_password)
shopify.ShopifyResource.activate_session(session)

product = shopify.Product.find(4826622918788)
print(product)