Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Querying Sanity using GraphQL

Info

GraphQL URL (Playground Available): https://czqk28jt.api.sanity.io/v1/graphql/dev_bk_us/default

  • Replace dev_bk_us with the {{stage}}_{{brand}}_{{country}} that you desire to query.

  • Sanity GraphQL can be hit via a POST request. Please reference the POST URL structure for each of the sample queries below.

  • Please use this playground to play with the queries below and examine the schema for fields you may wish to request.

...

Code Block
query getSanityOffers {
	LoyaltyOffersUI(id: "feature-loyalty-offers-ui-singleton") {
	# Available for all users.
    sortedSystemwideOffers {
      _id
      loyaltyEngineId
      name {
        enRaw
      }
    }
    # These are "templates", personalized offers get created based on this template.
    # You should use these only to display content (images, names, etc), and display only the actual offer from the engine.
    liveConfigOffers {
      _id
      loyaltyEngineId
      name {
        enRaw
      }
    }
  }
}

Example Rewards Query

Code Block
query getSanityRewards {
  RewardList(id:"reward-list-singleton") {
    rewardCategories {
      _id
      label {
        en
      }
      rewards {
        ... on Reward {
          _id
          name {
            en
          }
        }
      }
    }
  }
}

...

Querying Loyalty Engine

Info

GraphQL URL

...

(Playground Available): https://euc1-dev-bk-loyalty-middleware.rbictg.com/graphql

  • Replace dev-bk with the {{stage}}-{{brand}} that you desire to query. For all markets other than US/CA, you You will need to prefix the url URL with the AWS region that your market lives in. Please communicate with RBI reps to know which region your market is hosted. Example url

    • An example URL for ES (Spain) would be https://

    euc1
  • Make sure to set the x-ui-region header to the country you want to query:

...

  • Please use this playground to play with the queries below and examine the schema for fields you may wish to request.

  • Some where filters that may be relevant to Kiosk

    • ids - a collection of engine ids Engine IDs for offers/rewards. This is the loyaltyEngineId field on every sanity offer/reward document.

    • omitInvalids - This controls whether invalid incentives will be returned. Only incentives that failed “fixable” rules will be returned if this is set to false. A fixable rule is one that the user can change behavior to make the rule pass, like the minSpend, the user can add more items to their cart to meet the requirement. An absolute failure like date-band will not be returned regardless of what the value of this filter is

      • This is useful for displaying error / in-line messages in the UI

    • serviceMode - some incentives can only be redeemed if the service mode meets the required ruleset

    • storeId - some incentives can only be redeemed at certain stores

    • subtotalAmount = some incentives require a minimum spend

    • cartEntries - some incentives require certain items to be in the cart, this rule uses the sanity id of each rbi product

    • paymentMethod - some incentives require certain payment methods to be used

...

Code Block
query getLoyaltyOffers {
  loyaltyOffersV2(loyaltyId: "some-user-id<USER_LOYALTY_ID>", where: { omitInvalids: false }) {
    id
    name
    type
    sanityId
    errors {
      code
      ruleId
    }
  }
}

...

Code Block
{
  "data": {
    "loyaltyOffersV2": [
      {
        "id": "a4c24211-2d36-47be-bad8-8deea437dbfa",
        "name": "$6 Let's Get This Bacon Meal",
        "type": "GLOBAL",
        "sanityId": "AAA-AAA-AAA",
        "errors": null
      },
      {
        "id": "fbba4e93-eecd-42b6-a4ed-333856d47bda",
        "name": "Delivery Offer - $8 The Spicy One Meal",
        "type": "GLOBAL",
        "sanityId": "BBB-BBB-BBB",
        "errors": null
      },
      {
        "id": "2a7b2f20-1662-4854-9f4b-e9974200f294",
        "name": "Support 50% Discount Offer",
        "type": "PERSONALIZED",
        "sanityId": "CCC-CCC-CCC",
        "errors": null
      },
      {
        "id": "6646b80b-dea9-4bf4-81f5-390554926987",
        "name": "Loyalty Upsize Swap",
        "errors": [
          {
            "code": "unsatisfied-cart-requirements",
            "ruleId": "cart-requirement"
          }
        ]
      }
    ]
  }
}

...

Code Block
query getLoyaltyRewards {
  loyaltyRewards(loyaltyId: "some-user-id<USER_LOYALTY_ID>", where: { omitInvalids: false }) {
    id
    name
    errors {
      code
      ruleId
    }
  }
}

...