How to get session ID in orders REST API/GraphQL

Topic summary

A developer needs to map Shopify orders to user sessions for analytics, specifically to calculate unique sessions where orders are placed versus total unique sessions.

Current Challenge:

  • The Orders REST API/GraphQL lacks session ID fields
  • The session_hash field exists but is mostly NULL and unclear how to decode
  • No direct way to link orders to session identifiers

Proposed Workaround:
A suggested solution involves using the Ajax Cart API to add custom session data:

  1. Capture session information (browser IP + user ID + other identifiers) on the storefront
  2. Store this data in cart attributes via the Ajax Cart API
  3. Pass these attributes through to order note attributes during checkout
  4. Retrieve the session data from completed orders in the backend

Implementation Steps:

  • Use cart.js to check and update cart data with session identifiers
  • Proceed to checkout with embedded session information
  • Access the custom attributes in order data post-purchase

The approach requires a custom implementation rather than relying on native Shopify fields, as the platform doesn’t natively track session-to-order relationships.

Summarized with AI on November 8. AI used: claude-sonnet-4-5-20250929.

I’m new to shopify.

I need a way to map a particular order to user’s session. I.e what is the session ID in which that particular orders is placed.
Checking the REST API response of orders, there is no particular mapping like this.
There is a field called session_hash but it is mostly NULL value (even if it is not NULL how to decipher hash)

Is there any way to find this

  • Any particular field in Order REST API/GraphQL which can directly give session ID
  • Any custom way, where I can log an event just before checkout API is called for placing a new order
  • Any other hacky way, like combination of broswerIP + userID + to uniquely identify a unique user session in which an order is placed.

Basically I’m calculating an analytics : (sessions in which an order(s) is placed) vs total unique sessions

-----------

Link to order Rest API : Order (shopify.dev)
For Session ID I’m fetching it via & saving it into my backend:

ShopifyAnalytics.lib.user().traits().uniqToken

Hi @ajs540 ,

I think the order info does not have any fields related to user’s session ID. But, we can put additional info into order note attributes by putting info into cart attributes using Ajax Cart API

→ Make a request on Storefront

BSSCommerceB2B_0-1718873033143.png

→ Check cart data by storefront-domain/cart.js

→ Proceed Checkout and check order data

That what I can think about. Hope you can find out solution soon.