Conversation
docs/getting_started.md
Outdated
| For *non-embedded* apps, you can pass the cookies into `ShopifyAPI::Utils::SessionUtils.current_session_id(nil, cookies, true)` for online (user) sessions or `ShopifyAPI::Utils::SessionUtils.current_session_id(nil, cookies, false)` for offline (store) sessions. | ||
|
|
||
| #### Getting Session ID From Embedded Requests | ||
| For *embedded* apps, you can pass the auth header into `ShopifyAPI::Utils::SessionUtils.current_session_id(auth_header, nil, true)` for online (user) sessions or `ShopifyAPI::Utils::SessionUtils.current_session_id(auth_header, nil, false)` for offline (store) sessions. |
There was a problem hiding this comment.
Is it worth mentioning how to get the bearer token (e.g. calling authenticatedFetch from app bridge) here?
|
Where in the docs I can read more about |
This is the |
|
@nelsonwittwer do you think this would be something worth including somewhere in the docs? Thanks! This might be better line of code to link to: As someone who has been actively building Shopify apps for the past several years, it is still not clear how I can make Shopify API calls with the latest version of shopify_api gem outside of the request-response scope (in bg jobs for example). EDIT: I have the code written somewhere that works. If you need it, I can dig it up and share it here so that you can add it to documentation? |
|
@vfonic I'm having trouble making requests in background jobs as well. Have you had any luck with this since your last comment? |
|
Yes, I have it fully working. You can do: shop.with_shopify_session do
# any code that makes requests to Shopify REST or GraphQL API
endor session = ShopifyAPI::Auth::Session.new(shop: shop.shopify_domain, access_token: shop.shopify_token, scope: shop.access_scopes)
# and then
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
client.query(query:, variables:).body
# or
ShopifyAPI::Context.activate_session(session)
ShopifyAPI::Webhook.all.as_json
# or whatever you needSomething along these lines should work. In both cases |
Description
As noted in #1163, our docs for sessions are out of date. These changes better outline how sessions work within the ruby libraries.