Skip to content

DiscountCode

A DiscountCode is a code shoppers enter in a Cart: its id is the code (SUMMER25), stored in upper case and entered in any case. It takes percentOff or amountOff (in priceCurrency) off the eligible lines, or gives freeShipping, which your app applies; it applies from validFrom to validThrough, above a minimumOrderValue, to its eligibleOffers or eligibleCategories (all lines when neither), and to customers with one of its eligibleCustomerTags; maxUses and maxUsesPerCustomer limit how often. A cart's read shows the discount, or why the code doesn't apply; the checkout counts the use, and usesCount shows it. ObjectsGrid's own type: Schema.org has none. See Discount codes.

JSON Schema ยท ABAC object type DiscountCode

Example

Create one with POST /discountcodes:

{
  "id": "SUMMER25",
  "name": [
    {
      "at_language": "en",
      "at_value": "Summer sale"
    }
  ],
  "percentOff": 25,
  "validThrough": "2027-08-31T23:59:59Z",
  "minimumOrderValue": {
    "value": 50,
    "currency": "EUR"
  },
  "maxUsesPerCustomer": 1
}

Fields

Required: id, name.

Field Type Required Description
at_type DiscountCode JSON-LD @type, the object's type name.
at_id URL The object's ObjectsGrid URL, https://apis.objectsgrid.com/<path>/<id>, its JSON-LD @id: what References to it hold. Assigned by ObjectsGrid.
id string Yes The code, chosen by you, e.g. SUMMER25: 1 to 50 letters, digits, - and _, stored in upper case. Shoppers may enter it in any case. A code is used once in an Organization Account, even after a delete.
identifier string The object's id, as Schema.org identifier. Assigned by ObjectsGrid.
url URL The object's own URL, https://apis.objectsgrid.com/<path>/<id>. Assigned by ObjectsGrid.
name list of LanguageTaggedString Yes The DiscountCode name
description list of LanguageTaggedString What the code is for, e.g. the campaign
percentOff number The percentage taken off the eligible lines, e.g. 25
amountOff number The amount taken off the eligible lines, in priceCurrency
priceCurrency CurrencyCodeEnumeration The currency of amountOff
freeShipping boolean Whether it gives free shipping, which the app applies
validFrom date-time When it starts to apply
validThrough date-time When it stops applying
minimumOrderValue MonetaryAmount The least the eligible lines must total, in the currency given
eligibleOffers list of References to Offer The Offers it applies to; all when none and no eligibleCategories
eligibleCategories list of string The Product categories it applies to: a line applies when its product has one of them
eligibleCustomerTags list of Tag Tags of the customer's Person it requires, e.g. name tier, val gold: any one is enough
maxUses integer How many checkouts can use it in all
maxUsesPerCustomer integer How many checkouts of one customer can use it; a cart then needs a customer
usesCount integer How many checkouts used it. Set by the service at checkout, never written.
tags list of Tag Tags your ABAC policy decides on. Created empty when not sent, kept by a PUT that leaves them out, cleared by null or [].
meta ObjectMeta Read-only metadata: version, type, creation and last update.

REST API

Base URL https://apis.objectsgrid.com. Every request sends the X-ObjectsGrid-AccessPoint and Authorization: Bearer <access token> headers; see the REST API guide.

Operation Request
Create POST /discountcodes
List and search GET /discountcodes
Create up to 100 at once POST /discountcodes/batch
Retrieve GET /discountcodes/{id}
Retrieve as a JSON-LD document for your pages GET /discountcodes/{id} with Accept: application/ld+json; see JSON-LD for your pages
Replace PUT /discountcodes/{id}
Update some fields PATCH /discountcodes/{id}
Delete DELETE /discountcodes/{id}

The OpenAPI contract, with every parameter and response: DiscountCodes (JSON).

GraphQL

Endpoint POST https://apis.objectsgrid.com/graphql; see the GraphQL guide.

Operation Field
Query discountCode(id: ID!, version: String): DiscountCode
Query discountCodes(where: DiscountCodeWhereInput, orderBy: [DiscountCodeOrderByInput!], first: Int, after: String): DiscountCodeConnection!
Query discountCodesGroupBy(by: [DiscountCodeGroupByField!]!, where: DiscountCodeWhereInput, having: DiscountCodeHavingInput, orderBy: [DiscountCodeGroupByOrderByInput!], first: Int, after: String): DiscountCodeGroupByConnection!
Mutation createDiscountCode(input: CreateDiscountCodeInput!): DiscountCode!
Mutation updateDiscountCode(input: UpdateDiscountCodeInput!, expectedVersion: String): DiscountCode!
Mutation deleteDiscountCode(id: ID!, expectedVersion: String): Boolean!

Webhook events

Subscribe to these events in your webhook configuration to be called when a DiscountCode changes:

DiscountCodeCreated, DiscountCodeUpdated, DiscountCodePatched, DiscountCodeDeleted.