Skip to content

GraphQL API

The GraphQL API is the preferred way to work with ObjectsGrid's business objects: one endpoint, and every request asks for exactly the fields it needs.

Endpoint POST https://apis.objectsgrid.com/graphql (GraphQL over HTTP)
Headers X-ObjectsGrid-AccessPoint: EU or US, Authorization: Bearer <access token>
Playground apis.objectsgrid.com/playground
Schema schema.graphql, or introspection, which needs no token

Get an access token first; see Authentication. The GraphQL API serves business objects. Accounts, policies, access logs and enums are managed with the REST API.

Your first query

curl https://apis.objectsgrid.com/graphql \
  -H 'Content-Type: application/json' \
  -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"query": "{ products(first: 10) { items { id sku name { at_language at_value } } } }"}'
{
  "data": {
    "products": {
      "items": [
        {
          "id": "2b5f8f0e-1d0c-4d61-9a7e-5a1f0c3e9d21",
          "sku": "TRS-42",
          "name": [{ "at_language": "en", "at_value": "Trail Running Shoe" }]
        }
      ]
    }
  }
}

In the playground, put the headers in the Headers panel:

{
  "X-ObjectsGrid-AccessPoint": "EU",
  "Authorization": "Bearer <access token>"
}

Naming

Every object type follows the same pattern. For Product:

Operation Field
List products(where: ProductWhereInput, orderBy: [ProductOrderByInput!], first: Int, after: String): ProductConnection!
Group productsGroupBy(by: [ProductGroupByField!]!, where: ProductWhereInput, having: ProductHavingInput, orderBy: [ProductGroupByOrderByInput!], first: Int, after: String): ProductGroupByConnection!
Read one product(id: ID!, version: String): Product
Create createProduct(input: CreateProductInput!): Product!
Update updateProduct(input: UpdateProductInput!, expectedVersion: String): Product!
Delete deleteProduct(id: ID!, expectedVersion: String): Boolean!

Each page of the object reference lists the operations of its type.

Create, read, update and delete

mutation {
  createProduct(input: {
    sku: "TRS-42"
    name: [{ at_language: "en", at_value: "Trail Running Shoe" }]
    brand: { at_id: "https://apis.objectsgrid.com/brands/0f0b9a52-6d7e-4f4b-9d5e-3c1c2a7e8b11" }
    tags: [{ name: "department", val: "outdoor" }]
  }) {
    id
    meta { objectVersion createdAt createdBy }
  }
}
query {
  product(id: "2b5f8f0e-1d0c-4d61-9a7e-5a1f0c3e9d21") {
    id
    sku
    name { at_language at_value }
    brand { at_id ... on Brand { name { at_value } } }
    meta { objectVersion lastUpdatedAt }
  }
}
mutation {
  updateProduct(
    input: {
      id: "2b5f8f0e-1d0c-4d61-9a7e-5a1f0c3e9d21"
      name: [{ at_language: "en", at_value: "Trail Running Shoe, 2nd edition" }]
    }
    expectedVersion: "1763025002419837"
  ) {
    id
    meta { objectVersion }
  }
}
mutation {
  deleteProduct(id: "2b5f8f0e-1d0c-4d61-9a7e-5a1f0c3e9d21")
}

updateX changes the fields you send, and the fields you leave out keep their values. To clear a field or replace a whole object, use the REST API's PUT or PATCH.

References

A field that points to another object is typed ObjectsGridObject, the interface every object implements. Select the Reference's own fields, at_id, id and at_type, and the object's fields with a fragment on its type: the same request reads it.

query {
  order(id: "ord-123") {
    orderNumber
    orderItem {
      at_id
      at_type
      ... on Product { name { at_value } gtin13 }
      ... on Service { name { at_value } }
    }
    customer { ... on Organization { legalName } }
  }
}
  • at_id, id, at_type and __typename alone are answered from the reference, at no cost.
  • The objects a request points to are read together: one read per type, however many references point to it.
  • A computed field lists the objects that point to this one, as their own list does, with where, orderBy, first and after: product(id: "…") { review(first: 5, orderBy: [{ datePublished: desc }]) { items { reviewBody { at_value } } } }.
  • An external URL comes back as an UnresolvedObject, with the reference's fields only.
  • An object that can't be read, deleted or hidden from you by your ABAC policy, keeps its reference's fields, its other fields null, and the response has an error at its path with the code REFERENCE_UNRESOLVED. The rest of the response is answered.
  • A query follows references at most 6 levels of objects deep (QUERY_TOO_DEEP) and selects at most 500 object fields (QUERY_TOO_COMPLEX). Introspection is not limited.
  • Writes take a ReferenceInput: { at_id: "<url>" }, with at_type for a URL outside ObjectsGrid.

A Product, ProductGroup, Organization, Place, Service, Review, Offer, Brand, Rating, OfferCatalog, ServiceChannel, Event, MemberProgram, MemberProgramTier, Course or Demand also has jsonLd(lang: String), its Schema.org JSON-LD document for your page. See JSON-LD for your pages.

Free slots

availableSlots gives a provider's free times, for a booking page: the working hours of their EmployeeRoles (workSchedule, Schedules: days, times, time zone, repeatFrequency such as P2W for every other week, exceptDate for holidays) less their appointments (Reservations of no kind with that provider, not cancelled), as slots of duration between from and to, at most 31 days apart and 500 slots.

query {
  availableSlots(provider: "https://apis.objectsgrid.com/persons/p-7", from: "2027-01-11T00:00:00+01:00",
                 to: "2027-01-18T00:00:00+01:00", duration: "PT30M") { startTime endTime }
}

The appointments are read from search, seconds behind a write. A booking of a slot taken a moment ago is refused with CONFLICT (409 in REST), so book, then show the answer: the slot is the customer's only if the write succeeds.

Localized text

Text fields such as name and description hold one entry per language, as LanguageTaggedStrings. Select their subfields:

{ product(id: "...") { name { at_language at_value } } }

Filter, sort and page

Lists take a typed where and orderBy, and page with first and after, the previous page's pageInfo.endCursor:

{
  products(where: {color: {equals: "Blue"}}, orderBy: [{meta: {createdAt: desc}}], first: 20, after: "eyJ…") {
    items { id sku }
    pageInfo { endCursor hasNextPage }
    totalCount
  }
}

Select totalCount to count the objects the where matches, and use <types>GroupBy for groups with counts and aggregates. Lists has every condition and what your ABAC policy allows.

Optimistic concurrency

Two people editing the same object shouldn't overwrite each other. Read meta.objectVersion, and send it back unchanged as expectedVersion with updateX or deleteX. The write happens only if nobody changed the object since you read it; otherwise you get a PRECONDITION_FAILED error and nothing changes. Read the object again, reapply your change, and retry.

People have a few operations of their own: personsByEmail(email:) is an exact lookup, and erasePerson(id:) erases a person and answers when (see Personal data and erasure). In persons lists, and once a person is erased, their personal fields read as null.

To read an earlier version, pass its meta.objectVersion as version: product(id: "<id>", version: "1763025002419837"). Earlier versions stay readable after the object is deleted, and they carry the object's current tags. See the REST guide.

objectVersion is a string of digits. Compare it, don't compute with it.

Errors

GraphQL answers 200 for every operation that runs, also when it fails; the failure is in the errors array:

{
  "errors": [
    {
      "message": "The object is not valid",
      "path": ["createProduct"],
      "extensions": {
        "code": "BAD_USER_INPUT",
        "errorCode": "VALIDATION_FAILED",
        "type": "https://objectsgrid.com/docs/error-details/validation-failed/",
        "domain": "objectsgrid.com",
        "httpStatusCode": 400,
        "correlationId": "4bf92f3577b34da6a3ce929d0e0e4736",
        "reasons": ["/sku: required"]
      }
    }
  ],
  "data": null
}

extensions.errorCode is the error's code in Error details, the same as a REST error's code, with its page in type; act on it for what happened. extensions.code is a coarse category, as below:

Code Meaning
BAD_USER_INPUT The input isn't valid; reasons says why.
UNAUTHORIZED No valid access token, or your policy doesn't allow it.
FORBIDDEN Not allowed.
NOT_FOUND No object with that id.
CONFLICT The object kept changing while it was written.
PRECONDITION_FAILED expectedVersion is not the current version.
TOO_MANY_REQUESTS Rate limit or monthly spending cap reached.
INTERNAL_SERVER_ERROR Something went wrong on our side. Retry, and quote the correlationId if it persists.
REFERENCE_UNRESOLVED A referenced object can't be read: it is gone, or hidden from you. The rest is answered; see References.
QUERY_TOO_DEEP The query follows references more than 6 levels of objects deep.
QUERY_TOO_COMPLEX The query selects more than 500 object fields.

A request that doesn't parse or validate as GraphQL answers 400. Responses are application/graphql-response+json; send Accept: application/json to get plain JSON, in which case such a request answers 422. Every response carries a trace id in extensions.traceId; see Errors and troubleshooting.

Logs

Frontend log events are written with one mutation per batch and searched with a query; see Frontend logging.