# ObjectsGrid documentation, full text > Every page of the ObjectsGrid documentation (https://objectsgrid.com/docs/) in one file, in the order of its navigation. The summary is https://objectsgrid.com/llms.txt. The machine-readable files under https://objectsgrid.com/.well-known/ (discovery document, OpenAPI contracts, object catalog) are the source of truth: where they disagree with this text, they win. --- Source: https://objectsgrid.com/docs/ # ObjectsGrid documentation ObjectsGrid is a plug-and-play backend. You store standardized business objects (products, offers, orders, inventory, places, reviews and more) and read them back through a **GraphQL API** or **REST APIs**. You don't build or run a backend of your own. The objects follow [Schema.org](https://schema.org). Access is secured with **OAuth 2.0** access tokens and decided by your own **attribute-based access control (ABAC)** policy. Your data stays in the region you choose, the EU or the US.
- :lucide-rocket: **Quick start** --- Create your Organization Account, get an access token and store your first product in a few minutes. [:octicons-arrow-right-24: Start here](https://objectsgrid.com/docs/get-started/quick-start/) - :lucide-boxes: **Core concepts** --- Organization Accounts, regions, objects, accounts, tokens and policies: the ideas behind every API call. [:octicons-arrow-right-24: Learn the concepts](https://objectsgrid.com/docs/get-started/core-concepts/) - :lucide-braces: **GraphQL API** --- One endpoint for all business objects. Ask for exactly the fields you need. [:octicons-arrow-right-24: Use GraphQL](https://objectsgrid.com/docs/guides/graphql-api/) - :lucide-server: **REST APIs** --- One REST API per object type, with search, batch create and optimistic concurrency. [:octicons-arrow-right-24: Use REST](https://objectsgrid.com/docs/guides/rest-api/) - :lucide-shield-check: **Access control** --- Decide who may read and change which objects, and which fields they see, with policies in Rego. [:octicons-arrow-right-24: Write a policy](https://objectsgrid.com/docs/guides/access-control/) - :lucide-book-open: **Object reference** --- Every object type, its fields, its REST endpoints and its GraphQL operations. [:octicons-arrow-right-24: Browse the objects](https://objectsgrid.com/docs/objects/)
## What you can build - **Commerce backends.** [Products](https://objectsgrid.com/docs/objects/product/), [product groups](https://objectsgrid.com/docs/objects/product-group/) and [models](https://objectsgrid.com/docs/objects/product-model/), [offers](https://objectsgrid.com/docs/objects/offer/), [offer catalogs](https://objectsgrid.com/docs/objects/offer-catalog/), [orders](https://objectsgrid.com/docs/objects/order/), [inventory](https://objectsgrid.com/docs/objects/inventory/), [brands](https://objectsgrid.com/docs/objects/brand/), [reviews](https://objectsgrid.com/docs/objects/review/) and [ratings](https://objectsgrid.com/docs/objects/rating/). - **Business directories.** [Organizations](https://objectsgrid.com/docs/objects/organization/), [places](https://objectsgrid.com/docs/objects/place/) with opening hours, [services](https://objectsgrid.com/docs/objects/service/) and their [service channels](https://objectsgrid.com/docs/objects/service-channel/). - **Your own data.** [Generic objects](https://objectsgrid.com/docs/objects/generic-object/) for anything no built-in type covers, and [enums](https://objectsgrid.com/docs/objects/enum/) for the value lists of your app. - **App logging.** Send your web and mobile apps' errors and user events in batches, then search them. See [frontend logging](https://objectsgrid.com/docs/guides/frontend-logging/). - **Integrations.** Get a signed [webhook](https://objectsgrid.com/docs/guides/webhooks/) call whenever an object is created, changed or deleted. ## For AI agents and tools ObjectsGrid describes itself in machine-readable files at [objectsgrid.com/.well-known](https://objectsgrid.com/.well-known/index.json): the OpenAPI contracts, the JSON Schema object catalog, the GraphQL schema and the OAuth metadata. Where this documentation and those files disagree, the files win. A summary for language models is at [objectsgrid.com/llms.txt](https://objectsgrid.com/llms.txt). --- Source: https://objectsgrid.com/docs/get-started/ # Get started ObjectsGrid gives your web or mobile app a ready-made backend. You register once, get an access token, and start storing objects through the GraphQL API or the REST APIs. 1. **[Quick start](https://objectsgrid.com/docs/get-started/quick-start/).** Register your Organization Account and store your first product with `curl`, in about five minutes. 2. **[Start without signing in](https://objectsgrid.com/docs/get-started/start-without-signing-in/).** Or create an Organization Account with one request and no sign-in, and get three API keys: for trying ObjectsGrid out, and for AI agents. 3. **[Core concepts](https://objectsgrid.com/docs/get-started/core-concepts/).** The few ideas behind every request: Organization Accounts and regions, objects, accounts, tokens and policies. 4. **[Sign in with Google](https://objectsgrid.com/docs/get-started/login-with-google/)**, **[Sign in with Apple](https://objectsgrid.com/docs/get-started/sign-in-with-apple/)** and **[Sign in with Okta](https://objectsgrid.com/docs/get-started/sign-in-with-okta/).** Let the users of your own app, or your organization's people, sign in, and exchange their ID token for an ObjectsGrid access token. When you have the basics, the [guides](https://objectsgrid.com/docs/guides/) go deeper, and the [object reference](https://objectsgrid.com/docs/objects/) lists every object type. --- Source: https://objectsgrid.com/docs/get-started/quick-start/ # Quick start In this quick start you register your Organization Account, get an access token, and create and read a product. All you need is a Google account and `curl`. ## 1. Choose your region Your Organization Account and all its data live in one region, which you choose now and cannot change later: - `EU`: the European Union - `US`: the United States Every request sends the region in the `X-ObjectsGrid-AccessPoint` header. The examples below use `EU`. ## 2. Register your Organization Account !!! tip "No Google account at hand, or an AI agent?" Create an Organization Account with one request and no sign-in, and get three API keys at once: see [Start without signing in](https://objectsgrid.com/docs/get-started/start-without-signing-in/). Use its `user` API key as `$TOKEN` below. The easiest way is the [Admin site](https://admin.objectsgrid.com): sign in with Google and fill in the form. To do it with the API instead: 1. Open the [test token page](https://admin.objectsgrid.com/google_token.html), sign in with Google and copy the **ID token** it shows. ID tokens expire after about an hour. 2. Create the account with that ID token as the bearer token: ```bash curl -i -X POST https://apis.objectsgrid.com/organizationaccounts \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H 'Authorization: Bearer ' \ -d '{"name": "My test organization", "accessPoint": "EU"}' ``` The response is `201 Created`, with your new Organization Account in the body. Note its `id`, such as `org-123-4567`: you need it to sign in later. Registering also does three things for you: - It creates your **User Account** and makes you the account's **administrator**. - It creates a default **ABAC policy**, which gives everyone except administrators no access until you add rules. - It signs you in: the response's `Authorization` header holds an ObjectsGrid **access token**, `Bearer `. !!! tip "Not ready to use real data?" You don't need a real company. Register an Organization Account for trying things out, and a separate one for production later. Keep the access token in a shell variable for the next steps: ```bash export TOKEN='' ``` ## 3. Create a product === "GraphQL" ```bash curl https://apis.objectsgrid.com/graphql \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{"query": "mutation { createProduct(input: { sku: \"TRS-42\", name: [{ at_language: \"en\", at_value: \"Trail Running Shoe\" }] }) { id sku meta { objectVersion createdAt } } }"}' ``` === "REST" ```bash curl -i -X POST https://apis.objectsgrid.com/products \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{"sku": "TRS-42", "name": [{"at_language": "en", "at_value": "Trail Running Shoe"}]}' ``` ObjectsGrid assigns the product's `id` and returns it, with read-only metadata in `meta`. Text fields such as `name` are [localized](https://objectsgrid.com/docs/objects/language-tagged-string/): a list with one entry per language. ## 4. Read it back === "GraphQL" ```bash 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 } } } }"}' ``` === "REST" ```bash curl https://apis.objectsgrid.com/products/ \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" ``` You can also explore the GraphQL API in the browser with the [GraphQL playground](https://apis.objectsgrid.com/playground). Set the `X-ObjectsGrid-AccessPoint` and `Authorization` headers in its Headers panel. ## 5. Sign in again later Your access token lasts one hour. To get a new one, exchange a fresh Google ID token, with your Organization Account id as `client_id`: ```bash curl -X POST https://apis.objectsgrid.com/oauth2/token \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \ --data-urlencode 'subject_token=' \ -d subject_token_type=urn:ietf:params:oauth:token-type:id_token \ -d 'client_id=' ``` The response also holds a refresh token, which gets you new access tokens for three months without signing in again. See [Authentication](https://objectsgrid.com/docs/guides/authentication/). ## Next steps - **Your own app's users:** register your app with Google and add its client id to your Organization Account. See [Sign in with Google](https://objectsgrid.com/docs/get-started/login-with-google/). - **Servers and scripts:** create a [service account](https://objectsgrid.com/docs/accounts/service-account/) and sign in with its id and secret. See [Authentication](https://objectsgrid.com/docs/guides/authentication/#service-accounts). - **Who may do what:** add rules to your ABAC policy. See [Access control](https://objectsgrid.com/docs/guides/access-control/). - **Your data model:** browse the [object reference](https://objectsgrid.com/docs/objects/). --- Source: https://objectsgrid.com/docs/get-started/start-without-signing-in/ # Start without signing in You can create an Organization Account with one request, without a Google or Apple account: a person trying ObjectsGrid out, or an AI agent that found it through [/.well-known](https://objectsgrid.com/.well-known/index.json). It is the full product, not a sandbox: objects, tags, ABAC policies, webhooks and every other feature work as they do for any account. ## 1. Create the account ```bash curl -X POST https://apis.objectsgrid.com/organizationaccounts \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -d '{"name": "My test organization", "email": "ana@example.com"}' ``` No `Authorization` header. `email` is optional: give one to receive the link that binds an administrator (step 3). The answer is `201 Created`, the Organization Account with one more field, `bootstrap`: ```json { "id": "org-123-4567", "name": "My test organization", "accessPoint": "EU", "monthlyQuota": 50000, "verified": false, "bootstrap": { "admin": { "serviceAccount": {"id": "org-123-4567~…", "type": "secret", "secret": "…", "tags": [...]}, "accessToken": "", "expiresAt": "2027-02-20T10:00:00Z" }, "user": {"serviceAccount": {...}, "accessToken": "", "expiresAt": "…"}, "anonymous": {"serviceAccount": {...}, "accessToken": ""}, "bindingUrl": "https://admin.objectsgrid.com/?bindAccount=org-123-4567&accessPoint=EU&bindingCode=…", "notice": "Each accessToken is an API key: …" } } ``` !!! warning "Keep the response" The API keys, the secrets and the binding link are shown only now. ObjectsGrid can't show them again, and without a signed-in administrator, nobody can prove the account is theirs. Save them before you go on. ## 2. Use the API keys Each `accessToken` is an **API key**: an access token that works for 90 days, or, for the anonymous one, without expiry. Send it like any access token: ```bash curl https://apis.objectsgrid.com/products \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H 'Authorization: Bearer ' ``` The three keys belong to three [service accounts](https://objectsgrid.com/docs/accounts/service-account/), and the account's [ABAC policy](https://objectsgrid.com/docs/guides/access-control/) gives each its role: | Key | Tag | What it may do | |---|---|---| | `admin` | `security.role` = `organization-account-administrator` | Everything: it is an administrator, which the policy never limits | | `user` | `role` = `user` | Read and write every business object, Persons and Orders included. Not the webhook configuration, the accounts, the ABAC policy or the access logs | | `anonymous` | `role` = `anonymous` | Read the catalog (Products, Offers, Brands, Reviews, Organizations, Places, Services, Enums and the like) and send [frontend logs](https://objectsgrid.com/docs/guides/frontend-logging/). Nothing else: it is the key you may ship in a web page | The policy is an ordinary policy: read it with `GET /abacpolicies/abac-policy--` and change it with the admin key, to try other rules. Tags and the policy decide what each key may do; the key only says who is calling. An API key follows its service account: disable or delete the account, and its key stops working within a minute; retag it, and the key carries the new tags. After 90 days, the admin and user service accounts get access tokens with their `id` and `secret` (`POST /oauth2/token`, `grant_type=client_credentials`). The anonymous key keeps working: it is public, meant for your web pages. Before you ship it, list your sites in its service account's `allowedOrigins` and give it a `monthlyRequestLimit`. See [Anonymous access](https://objectsgrid.com/docs/guides/authentication/#anonymous-access). ## 3. Become the administrator The account is **unverified** until a person who signs in with Google or Apple becomes its administrator. While it is unverified: - it may make at most **50,000 requests a month**, the [free tier](https://objectsgrid.com/pricing/): it is never billed; - nobody can sign in to it with Google, Apple or Okta, apart from the binding below, which takes a Google or Apple sign-in. To bind an administrator, either: - open the `bindingUrl` and sign in with Google or Apple. The link works once, for 30 days; with an `email`, it was also emailed to that address. Whoever opens it first becomes the administrator: bind it yourself right away; - or send your Google or Apple ID token with the admin API key: ```bash curl -X POST https://apis.objectsgrid.com/organizationaccounts/org-123-4567/administrator \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H 'Authorization: Bearer ' \ -d '{"idToken": ""}' ``` The answer is `201` with your new [UserAccount](https://objectsgrid.com/docs/accounts/user-account/), an administrator. The account is now verified (`verified: true`): the 50,000 limit is lifted, your `monthlyQuota` is your spending cap, and the app you signed in with is added to `identityProviders`, so you sign in with it from now on. Everything the account holds stays: objects, policy, service accounts and keys. Binding works once: afterwards the operation answers `409`. ## Limits - **Creation:** 5 accounts an hour and 20 a day from one address (an IPv6 address counts as its /64), and a daily limit for the whole platform; past them, `429`. - **Emails:** at most one a day to an address, whatever the number of accounts created with it. - **No recovery without a binding:** an account nobody has bound has no owner ObjectsGrid can recognize. Keep the create response, and bind an administrator early. ## For AI agents Everything an agent needs is machine-readable: the [discovery document](https://objectsgrid.com/.well-known/index.json) says how to create an account, the [OrganizationAccounts contract](https://objectsgrid.com/.well-known/openapi/OrganizationAccounts/v1/openapi.json) describes the request and the `bootstrap` response, and [llms.txt](https://objectsgrid.com/llms.txt) summarizes the platform. An agent can create an account, store objects, tag them, write a policy and test it with the three keys, with no person involved; a person binds an administrator when the work is to be kept. --- Source: https://objectsgrid.com/docs/get-started/core-concepts/ # Core concepts ObjectsGrid is a backend you use through APIs. Your app stores standardized objects, and ObjectsGrid keeps them, secures them, makes them searchable and tells you when they change. These are the concepts every request involves. ## Organization Account: your tenant An **[Organization Account](https://objectsgrid.com/docs/accounts/organization-account/)** is your space on ObjectsGrid. Everything you create belongs to it: objects, accounts, your access policy, your webhook configuration. Organization Accounts are isolated from each other. Its id looks like `org-123-4567`. Most teams use one Organization Account per environment, for example one to test with and one for production. ## Regions and access points You choose where your data lives when you register: the **EU** or the **US**. This is your Organization Account's **access point**. Every request names it in a header, and is served and stored in that region: ```http X-ObjectsGrid-AccessPoint: EU ``` Within its region, each access point runs in two cloud regions, so your app stays online when one of them fails. ## Objects ObjectsGrid stores **objects** of standard types, modeled on [Schema.org](https://schema.org): [Product](https://objectsgrid.com/docs/objects/product/), [Offer](https://objectsgrid.com/docs/objects/offer/), [Order](https://objectsgrid.com/docs/objects/order/), [Inventory](https://objectsgrid.com/docs/objects/inventory/), [Organization](https://objectsgrid.com/docs/objects/organization/), [Place](https://objectsgrid.com/docs/objects/place/) and [more](https://objectsgrid.com/docs/objects/). For data no standard type covers there are [GenericObjects](https://objectsgrid.com/docs/objects/generic-object/), and [Enums](https://objectsgrid.com/docs/objects/enum/) for your value lists. Every stored object has: - an `id`, assigned by ObjectsGrid, - `tags`, the attributes your access policy decides on, - read-only `meta`: its version, type, and who created and last changed it, and when. Objects link to each other with [References](https://objectsgrid.com/docs/objects/reference/): a product's `brand` is `{"at_id": "https://apis.objectsgrid.com/brands/", "id": "", "at_type": "Brand"}`. In GraphQL one query reads an object and the objects it points to. Read [The data model](https://objectsgrid.com/docs/guides/data-model/) for the details. ## Two APIs, one set of objects - The **[GraphQL API](https://objectsgrid.com/docs/guides/graphql-api/)** is the preferred way to work with business objects: one endpoint, `https://apis.objectsgrid.com/graphql`, where each request asks for exactly the fields it needs. - The **[REST APIs](https://objectsgrid.com/docs/guides/rest-api/)** give each object type its own resource, such as `https://apis.objectsgrid.com/products`, with search, batch create and conditional writes. Accounts, policies and access logs are managed through REST only. Both APIs work on the same stored objects: a product created with GraphQL can be read with REST, and the other way round. ```mermaid flowchart LR app["Your app"] -->|GraphQL| gql["GraphQL API
/graphql"] app -->|REST| rest["REST APIs
/products, /offers, ..."] admin["Your administrators
and servers"] -->|REST| rest gql --> rest rest --> store[("Your objects
in your region")] ``` ## Accounts: who calls Every request is made by an **account** of your Organization Account: | Account | Who uses it | How it signs in | |---|---|---| | [User Account](https://objectsgrid.com/docs/accounts/user-account/) | People using your app | With an ID token from Google, exchanged for an access token | | [Service Account](https://objectsgrid.com/docs/accounts/service-account/), type `secret` | Your servers, scripts and scheduled jobs | With its id and secret | | [Service Account](https://objectsgrid.com/docs/accounts/service-account/), type `public` | Anonymous visitors of your app | With its id only | A User Account is created automatically the first time a person signs in. ## Access tokens Accounts sign in at the OAuth 2.0 token endpoints and get an **access token**, which they send with every request: ```http Authorization: Bearer ``` Access tokens last one hour. User Accounts also get a refresh token to get new access tokens without signing in again. See [Authentication](https://objectsgrid.com/docs/guides/authentication/). ## Access control: your ABAC policy What an account may do is decided by your Organization Account's **[ABAC policy](https://objectsgrid.com/docs/accounts/abac-policy/)**: rules written in [Rego](https://www.openpolicyagent.org/docs/latest/policy-language/) that compare the `tags` of the account with the `tags` of the objects. For example: *members of the marketing department may update brands tagged `department: marketing`.* Policies can also hide individual fields from some readers. **Administrators** are not subject to the policy. The person who registered the Organization Account is its first administrator. See [Access control](https://objectsgrid.com/docs/guides/access-control/). ## Events and webhooks Every change to an object produces an event, such as `ProductCreated` or `OrderPatched`. Configure a [webhook](https://objectsgrid.com/docs/guides/webhooks/) to have ObjectsGrid deliver the events you choose to your HTTPS endpoint, signed so you can check they come from ObjectsGrid. ## Audit and usage - Every request is recorded as an [AccessLogEntry](https://objectsgrid.com/docs/accounts/access-log-entry/): who called, what, when, and what was allowed or denied. - Every response carries a **correlation id** to quote when something goes wrong; see [Errors and troubleshooting](https://objectsgrid.com/docs/guides/errors-and-troubleshooting/). - Your Organization Account has a monthly spending cap that you set; see [Usage and limits](https://objectsgrid.com/docs/guides/usage-and-limits/). --- Source: https://objectsgrid.com/docs/get-started/login-with-google/ # Sign in with Google Your users sign in to your app with their Google account. Your app receives an **ID token** from Google and exchanges it for an ObjectsGrid **access token**, which it then sends with every API request. ObjectsGrid creates the user's [User Account](https://objectsgrid.com/docs/accounts/user-account/) on their first sign-in. This guide takes you through it in four steps: 1. Register your app with Google and get its **client id**. 2. Add the Sign in with Google button to your app. 3. Register the client id with your Organization Account. 4. Exchange the ID token for an access token. ```mermaid sequenceDiagram participant User participant App as Your app participant Google participant OG as ObjectsGrid User->>App: Clicks "Sign in with Google" App->>Google: Sign-in request with your client id Google-->>App: ID token App->>OG: POST /oauth2/token with the ID token OG-->>App: Access token and refresh token App->>OG: API requests with Authorization: Bearer ``` ## 1. Register your app with Google You need a [Google Cloud](https://cloud.google.com) account. It's best to create a Google Cloud project for your app: in the [Google Cloud console](https://console.cloud.google.com), open the project list at the top left and choose **New project**. **Start the Google Auth Platform.** Open [Google Auth Platform](https://console.cloud.google.com/auth) and click **Get started**. ![Google Auth Platform overview with the Get started button](../assets/images/login-with-google/01-google-auth-platform-get-started.png) **App information.** Enter your app's name and the support email address your users can write to, then click **Next**. ![App information form with app name and user support email](../assets/images/login-with-google/02-app-information.png) **Audience.** Choose **External**, so that any Google user can sign in, and click **Next**. ![Audience step with External selected](../assets/images/login-with-google/03-audience-external.png) **Contact information.** Enter the email address Google should use to contact you, and click **Next**. ![Contact information step](../assets/images/login-with-google/04-contact-information.png) **Finish.** Accept the Google API Services User Data Policy, click **Continue**, then **Create**. ![Agreement to the Google API Services User Data Policy](../assets/images/login-with-google/05-agree-to-policy.png) ![Create button of the Google Auth Platform setup](../assets/images/login-with-google/06-create.png) ![Confirmation that the OAuth configuration was created](../assets/images/login-with-google/07-created.png) **Branding.** Enter your app's branding, such as its logo and home page, and click **Save**. ![Branding page of the Google Auth Platform](../assets/images/login-with-google/08-branding.png) **Audience page.** Leave it as it is for now. When sign-in works, come back here to publish your app. ![Audience page with the app in testing](../assets/images/login-with-google/09-audience-testing.png) **Create a client.** In **Clients**, click **Create client**. ![Clients page with the Create client button](../assets/images/login-with-google/10-create-client.png) Choose the application type **Web application** and fill in: - **Authorized JavaScript origins**: your app's origin, such as `https://app.example.com`. - **Authorized redirect URIs**: the page that shows the sign-in button, often your home or login page. Click **Create**. ![Client details with authorized JavaScript origins and redirect URIs](../assets/images/login-with-google/11-client-details.png) **Copy the client id.** Google shows the client id and a client secret. You only need the **client id**, which ends in `.apps.googleusercontent.com`. ![Created OAuth client showing the client id](../assets/images/login-with-google/12-client-id.png) Leave the **Data Access** page unchanged: sign-in needs no extra scopes. The **Verification Center** then shows *Verification not required*. ![Verification Center showing Verification not required](../assets/images/login-with-google/13-verification-not-required.png) ## 2. Add the button to your app Google's [Sign in with Google for Web](https://developers.google.com/identity/gsi/web/guides/overview) library draws the button and hands your page the ID token. A minimal page, like the [ObjectsGrid test token page](https://admin.objectsgrid.com/google_token.html): ```html Sign in
``` The two `div` elements come from Google's library: the first configures it with your client id, the second is the button. ![The two Google Identity Services elements in the page](../assets/images/login-with-google/14-google-sdk-sections.png) When the user signs in, Google calls your callback. The ID token is `response.credential`: ![The credential field of Google's response holds the ID token](../assets/images/login-with-google/15-id-token-credential.png) ## 3. Register the client id with ObjectsGrid ObjectsGrid accepts an ID token only if it was issued to an app your Organization Account lists in its `identityProviders`, so other websites can't sign your users in to your account. Your Organization Account starts with the app you registered with; add your own app's client id. As an administrator, read your Organization Account, add your client id to the Google entry of `identityProviders`, and replace it: ```bash curl https://apis.objectsgrid.com/organizationaccounts/ \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" ``` ```bash curl -X PUT https://apis.objectsgrid.com/organizationaccounts/ \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{ "name": "Northpeak Outdoor", "accessPoint": "EU", "identityProviders": [ { "issuer": "https://accounts.google.com", "clientIds": ["", ".apps.googleusercontent.com"] } ] }' ``` Send the whole account you read, with your change. Keep the client ids already listed unless you want to stop them from signing in. ## 4. Exchange the ID token for an access token Your app sends the ID token to the token endpoint, as a JSON object or form-encoded. `client_id` is your Organization Account id: ```javascript async function exchangeForAccessToken(idToken) { const response = await fetch("https://apis.objectsgrid.com/oauth2/token", { method: "POST", headers: { "Content-Type": "application/json", "X-ObjectsGrid-AccessPoint": "EU", }, body: JSON.stringify({ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange", subject_token: idToken, subject_token_type: "urn:ietf:params:oauth:token-type:id_token", client_id: "", }), }); const { access_token, expires_in, refresh_token } = await response.json(); // Send access_token with every API request; use refresh_token before it expires. } ``` The response is `200` with an access token for one hour and a refresh token for three months. If you get `400` with `"error": "invalid_grant"`, check that the client id is in your `identityProviders` and that the ID token hasn't expired. See [Authentication](https://objectsgrid.com/docs/guides/authentication/) for refreshing and revoking tokens. ## Publish your app While your Google app is in testing, only the test users you list can sign in. When sign-in works, go to the **Audience** page of the Google Auth Platform and publish the app. --- Source: https://objectsgrid.com/docs/get-started/sign-in-with-apple/ # Sign in with Apple Your users sign in to your app with their Apple ID. As with [Google](https://objectsgrid.com/docs/get-started/login-with-google/), your app receives an **ID token**, from Apple this time, and exchanges it for an ObjectsGrid **access token**. ObjectsGrid creates the user's [User Account](https://objectsgrid.com/docs/accounts/user-account/) on their first sign-in. If your iOS app offers Sign in with Google, Apple's App Store Review Guidelines (4.8) ask it to offer an equivalent privacy-focused sign-in too: Sign in with Apple is one. This guide takes you through it in four steps: 1. Register your app with Apple: a **Services ID** for a website, the **bundle id** for an iOS app. 2. Add the Sign in with Apple button to your app. 3. Register the Services ID or bundle id with your Organization Account. 4. Exchange the ID token for an access token. ```mermaid sequenceDiagram participant User participant App as Your app participant Apple participant OG as ObjectsGrid User->>App: Clicks "Sign in with Apple" App->>Apple: Sign-in request with your Services ID and a nonce Apple-->>App: ID token App->>OG: POST /oauth2/token with the ID token and the nonce OG-->>App: Access token and refresh token App->>OG: API requests with Authorization: Bearer ``` ## 1. Register your app with Apple You need a membership of the [Apple Developer Program](https://developer.apple.com/programs/). In [Certificates, Identifiers & Profiles](https://developer.apple.com/account/resources/identifiers/list): 1. **App ID.** Under **Identifiers**, click **+**, choose **App IDs**, then **App**. Give it a description and an explicit **bundle id**, such as `com.example.shop`, tick **Sign in with Apple**, and register it. An iOS app signs in with this bundle id. 2. **Services ID**, for a website. Click **+** again and choose **Services IDs**. Give it a description, which users may see when they sign in, and an identifier different from the bundle id, such as `com.example.shop.web`. Register it, open it, tick **Sign in with Apple** and click **Configure**: - **Primary App ID**: the App ID of step 1. - **Domains and Subdomains**: your site's host name, such as `shop.example.com`, without `https://`. - **Return URLs**: the page that shows the button, such as `https://shop.example.com`. Apple refuses `localhost`. Click **Next**, **Done**, **Continue** and **Save**. Use one Services ID per environment, as you would one Google client per environment. 3. **Email relay.** Users may hide their email: Apple then gives your app an address such as `…@privaterelay.appleid.com`, which forwards to them. To send them email, register the domains and addresses you send from under **Services**, **Sign in with Apple for Email Communication**; Apple accepts only mail that passes SPF for them. ObjectsGrid only verifies the ID tokens Apple issues, with Apple's public keys: you don't create a Sign in with Apple key for it. ## 2. Add the button to your app On the web, Apple's [Sign in with Apple JS](https://developer.apple.com/documentation/signinwithapplejs) draws the button. In popup mode it hands your page the ID token, so no server of yours receives Apple's form post. Generate a fresh **nonce** for every sign-in and give it to Apple; you send the same value to ObjectsGrid. ```html Sign in
``` Use Apple's button as it is: Apple's [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/sign-in-with-apple) allow only its black, white and outlined styles. In an iOS app, `ASAuthorizationAppleIDProvider` gives you the ID token (`identityToken`) the same way. **The name.** Apple doesn't put the user's name in the ID token; it gives it to your app once, on the first sign-in only. ObjectsGrid takes the name from Google's ID tokens, but has none from Apple's: a User Account created with Apple gets a [Person](https://objectsgrid.com/docs/objects/person/) without a name. If you ask for it (`scope: "name email"`), save it yourself and set it on the Person with `PATCH /persons/{id}`. ## 3. Register the Services ID with ObjectsGrid ObjectsGrid accepts an ID token only if it was issued to an app your Organization Account lists in its `identityProviders`. As an administrator, read your Organization Account and add an Apple entry with your Services ID and, for an iOS app, its bundle id, then replace it: ```bash curl -X PUT https://apis.objectsgrid.com/organizationaccounts/ \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{ "name": "Northpeak Outdoor", "accessPoint": "EU", "identityProviders": [ {"issuer": "https://accounts.google.com", "clientIds": [""]}, {"issuer": "https://appleid.apple.com", "clientIds": ["com.example.shop.web", "com.example.shop"]} ] }' ``` Send the whole account you read, with your change, and keep the apps already listed unless you want to stop them from signing in. ## 4. Exchange the ID token for an access token The exchange is the same as for Google; send the nonce you gave Apple too: ```javascript async function exchangeForAccessToken(idToken, nonce) { const response = await fetch("https://apis.objectsgrid.com/oauth2/token", { method: "POST", headers: {"Content-Type": "application/json", "X-ObjectsGrid-AccessPoint": "EU"}, body: JSON.stringify({ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange", subject_token: idToken, subject_token_type: "urn:ietf:params:oauth:token-type:id_token", client_id: "", nonce: nonce, }), }); const { access_token, expires_in, refresh_token } = await response.json(); } ``` The response is `200` with an access token for one hour and a refresh token for three months. A `400` with `"error": "invalid_grant"` means the Services ID or bundle id isn't in your `identityProviders`, the ID token has expired, its email isn't verified, or its nonce isn't the one you sent. ## Signing in with both Google and Apple ObjectsGrid never joins accounts by email: a person who signed up with Google and then signs in with Apple, with the same address, is refused with `409`, since another account already uses it; one who hid their email gets a second, separate account instead. To use both, the person signs in with the first provider and adds the second to their own account, with its ID token and their access token: ```bash curl -X POST https://apis.objectsgrid.com/useraccounts//identities \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer " \ -d '{"idToken": "", "nonce": ""}' ``` From then on, either sign-in opens the same account. See [Authentication](https://objectsgrid.com/docs/guides/authentication/#two-ways-to-sign-in). ## When a user deletes their account If your app lets users delete their account, Apple requires it to revoke the user's Apple tokens too. Only your app holds them, so your app calls Apple's [token revocation](https://developer.apple.com/documentation/sign_in_with_apple/revoke_tokens) endpoint; ObjectsGrid keeps no Apple token. --- Source: https://objectsgrid.com/docs/get-started/sign-in-with-okta/ # Sign in with Okta Your organization's people sign in to your app with their Okta account. As with [Google](https://objectsgrid.com/docs/get-started/login-with-google/) and [Apple](https://objectsgrid.com/docs/get-started/sign-in-with-apple/), your app receives an **ID token**, from your own Okta org this time, and exchanges it for an ObjectsGrid **access token**. ObjectsGrid creates the person's [User Account](https://objectsgrid.com/docs/accounts/user-account/) on their first sign-in. The sign-in itself happens between your app and Okta. ObjectsGrid never sees a password and isn't an identity provider: it only checks the ID tokens your Okta org issues, with the keys your Okta org publishes. This guide takes you through it in four steps: 1. Create an app integration in Okta and find your issuer. 2. Sign people in with Okta in your app. 3. Register your Okta issuer and client ID with your Organization Account. 4. Exchange the ID token for an access token. ```mermaid sequenceDiagram participant User participant App as Your app participant Okta as Your Okta org participant OG as ObjectsGrid User->>App: Clicks "Sign in" App->>Okta: Authorization code flow with PKCE Okta-->>App: ID token (and Okta's own access token) App->>OG: POST /oauth2/token with the ID token OG->>Okta: Okta's public keys, fetched once and cached OG-->>App: Access token and refresh token App->>OG: API requests with Authorization: Bearer ``` ## 1. Create an app integration in Okta In the Okta Admin Console, go to **Applications**, **Applications**, and click **Create App Integration**: 1. Choose **OIDC - OpenID Connect**, then the type of your app: **Single-Page Application** for an app in the browser, **Native Application** for a mobile or desktop app, **Web Application** for an app with its own server. 2. If Okta asks how the client is defined, keep the option where Okta assigns and manages the client ID. 3. Keep the **Authorization Code** grant, and add **Refresh Token** so Okta's SDK can renew the person's Okta tokens without sending them back to the sign-in page. 4. Under **Sign-in redirect URIs**, add the page of your app that receives the sign-in, such as `https://shop.example.com/login/callback`. 5. Under **Assignments**, choose who may sign in, such as a group of your organization's people. Save, and note the app's **Client ID**, such as `0oa1b2c3d4EXAMPLE`. ObjectsGrid needs no client secret. **Your issuer** is the URL your Okta ID tokens carry as `iss`. It is one of: - `https://`, such as `https://acme.okta.com`, for Okta's org authorization server, which every Okta org has; - `https:///oauth2/`, such as `https://acme.okta.com/oauth2/default`, if your app uses a custom authorization server. If your Okta org uses a custom URL domain, such as `login.acme.com`, the issuer carries that domain instead. To check, open `/.well-known/openid-configuration` in a browser: its `issuer` field must be exactly the URL you register in step 3. ## 2. Sign people in with Okta Use Okta's SDK for your platform. In the browser, [Okta Auth JS](https://github.com/okta/okta-auth-js) runs the authorization code flow with PKCE and gives you the ID token: ```javascript import { OktaAuth } from "@okta/okta-auth-js"; const oktaAuth = new OktaAuth({ issuer: "https://acme.okta.com/oauth2/default", // your issuer clientId: "0oa1b2c3d4EXAMPLE", // your app integration's client ID redirectUri: "https://shop.example.com/login/callback", scopes: ["openid", "email", "profile", "offline_access"], pkce: true, }); // on your sign-in button await oktaAuth.signInWithRedirect(); // on the callback page await oktaAuth.handleLoginRedirect(); const idToken = oktaAuth.getIdToken(); ``` Ask for the **`email`** scope: ObjectsGrid needs the person's email to create their User Account. `offline_access` lets Okta's SDK renew the person's Okta tokens in the background. ## 3. Register your Okta issuer with ObjectsGrid ObjectsGrid accepts an ID token only if it was issued to an app your Organization Account lists in its `identityProviders`. As an administrator, read your Organization Account and add an entry with your issuer and your app's client ID, then replace it: ```bash curl -X PUT https://apis.objectsgrid.com/organizationaccounts/ \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{ "name": "Northpeak Outdoor", "accessPoint": "EU", "identityProviders": [ {"issuer": "https://accounts.google.com", "clientIds": [""]}, {"issuer": "https://acme.okta.com/oauth2/default", "clientIds": ["0oa1b2c3d4EXAMPLE"]} ] }' ``` Send the whole account you read, with your change, and keep the apps already listed unless you want to stop them from signing in. ObjectsGrid checks your issuer when you add it, so a mistake shows straight away rather than at the first sign-in. The request is refused with `400`, saying why, when: - the issuer isn't an `https` URL, or has a port, a query, a fragment or a trailing `/`; - its discovery document, `/.well-known/openid-configuration`, can't be read within 5 seconds, redirects, or is on an address that isn't public; - the document names another issuer: write the issuer exactly as your ID tokens carry it; - the document doesn't publish its keys on `https`, or doesn't list `RS256`, which Okta always uses. An Organization Account can list up to 3 issuers of its own, besides Google and Apple. Creating an Organization Account and binding its administrator still take a Google or Apple sign-in. ## 4. Exchange the ID token for an access token The exchange is the same as for Google and Apple: ```javascript async function exchangeForAccessToken(idToken) { const response = await fetch("https://apis.objectsgrid.com/oauth2/token", { method: "POST", headers: {"Content-Type": "application/json", "X-ObjectsGrid-AccessPoint": "EU"}, body: JSON.stringify({ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange", subject_token: idToken, subject_token_type: "urn:ietf:params:oauth:token-type:id_token", client_id: "", }), }); const { access_token, expires_in, refresh_token } = await response.json(); } ``` The response is `200` with an access token for one hour and a refresh token. A `400` with `"error": "invalid_grant"` means the issuer or client ID isn't in your `identityProviders`, the ID token has expired, or its nonce isn't the one you sent. **Email verification.** Okta leaves `email_verified` out of an ID token it issues together with an access token, which is how apps get them. For an issuer of your own, ObjectsGrid accepts an ID token without `email_verified`: you chose to trust your Okta directory. An ID token that says `email_verified` is `false` is still refused. ObjectsGrid finds a person's User Account by issuer and subject, never by email. ## How long a sign-in lasts When someone leaves your organization and you remove them in Okta, Okta stops signing them in, but ObjectsGrid doesn't hear about it: their ObjectsGrid refresh token keeps working until it runs out. Set how long a sign-in lasts with your Organization Account's `refreshTokenLifetimeHours`, from 1 to 2400 hours (100 days): ```bash curl -X PUT https://apis.objectsgrid.com/organizationaccounts/ \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{"name": "Northpeak Outdoor", "accessPoint": "EU", "refreshTokenLifetimeHours": 12}' ``` With 12, a person signed in at 09:00 can refresh until 21:00; then a refresh is refused with `invalid_grant`, and your app has them sign in with Okta again. Okta's SDK usually does that without a prompt while their Okta session lasts, and refuses once they have been removed. The lifetime counts from the sign-in, however often your app refreshes, and applies to every sign-in of your Organization Account, Google and Apple included. Without it, a refresh token lasts 100 days from when it was issued, as before. To cut someone off at once, an administrator disables their User Account: their access stops within the hour, when their access token expires. ## Before you change your issuer ObjectsGrid finds a person's User Account by their issuer and subject. If your issuer changes, for example when your Okta org moves to a custom URL domain, people signing in with the new issuer get new, empty User Accounts. ObjectsGrid doesn't move accounts from one issuer to another: plan the change before you have User Accounts that matter, or [contact us](https://objectsgrid.com/docs/support/). ## Troubleshooting | What you see | Why | | --- | --- | | `400` when you add the issuer, "its discovery document names another issuer" | The issuer isn't written exactly as your ID tokens carry it: check `iss` in a decoded ID token | | `400` when you add the issuer, "the issuer was asked less than a minute ago" | ObjectsGrid fetches an issuer's documents at most once a minute; wait a minute and try again | | `invalid_grant` on the exchange, the token issued to an app not registered | The app's client ID isn't under your issuer in `identityProviders` | | `400` on a first sign-in, "the token's 'email' claim is missing" | Your app didn't ask Okta for the `email` scope | | `invalid_grant` on a refresh, "this sign-in has ended" | The sign-in is older than `refreshTokenLifetimeHours`: sign in with Okta again | --- Source: https://objectsgrid.com/docs/guides/ # Guides These guides explain how ObjectsGrid works and how to use it well. New to ObjectsGrid? Start with the [quick start](https://objectsgrid.com/docs/get-started/quick-start/). | Guide | What you learn | |---|---| | [Authentication](https://objectsgrid.com/docs/guides/authentication/) | Get access tokens for users, servers and anonymous visitors; refresh and revoke them. | | [Access control](https://objectsgrid.com/docs/guides/access-control/) | Write the ABAC policy that decides who may read and change which objects and fields. | | [GraphQL API](https://objectsgrid.com/docs/guides/graphql-api/) | Query and change business objects through one endpoint. | | [REST API](https://objectsgrid.com/docs/guides/rest-api/) | Create, read, replace, patch, delete, search and batch-create objects; conditional writes. | | [The data model](https://objectsgrid.com/docs/guides/data-model/) | How objects follow Schema.org: references, localized text, tags and metadata. | | [Webhooks](https://objectsgrid.com/docs/guides/webhooks/) | Get signed events when objects change, and verify them. | | [Frontend logging](https://objectsgrid.com/docs/guides/frontend-logging/) | Send your app's errors and events in batches, and search them. | | [Carts and checkout](https://objectsgrid.com/docs/guides/carts-and-checkout/) | Keep shoppers' carts priced from your Offers, check them out into Orders, record payments, and define return and shipping policies once. | | [Configuration and feature flags](https://objectsgrid.com/docs/guides/configuration-and-feature-flags/) | Keep your apps' settings per environment, toggle features for some users or all, and poll them for free. | | [Usage and limits](https://objectsgrid.com/docs/guides/usage-and-limits/) | Your monthly spending cap, rate limits and size limits. | | [Errors and troubleshooting](https://objectsgrid.com/docs/guides/errors-and-troubleshooting/) | Error responses and their codes, correlation ids and request tracing. | | [Explain your API's errors](https://objectsgrid.com/docs/guides/error-catalog/) | Keep your own API's error codes and their explanations, in every language, for people and agents. | | [Hotels and rentals](https://objectsgrid.com/docs/guides/hotels-and-rentals/) | Model a hotel or holiday rentals: rooms as Accommodations, prices per night, stays that never double-book a room. | | [Restaurants and menus](https://objectsgrid.com/docs/guides/restaurants-and-menus/) | Menus with sections and dishes, diets, nutrition and the EU's 14 allergens, prices and ordering, a Schema.org menu for Google. | | [Car dealers](https://objectsgrid.com/docs/guides/car-dealers/) | Cars as Products of a vehicle kind, with VIN, mileage, fuel and engine, searched by any of them. | | [Real estate listings](https://objectsgrid.com/docs/guides/real-estate-listings/) | Properties for sale or to rent: the property, its listings and Offers, search by bedrooms and size. | | [Wishlists, questions and messages](https://objectsgrid.com/docs/guides/wishlists-questions-messages/) | Shoppers' wishlists and your own lists, questions and answers about what you sell, conversations whose words are erased with the customer. | | [Discount codes](https://objectsgrid.com/docs/guides/discount-codes/) | Percent or amount off, dates, minimums, eligible offers and customers, limits; shown on the cart, counted at checkout. | | [Check-ins](https://objectsgrid.com/docs/guides/check-ins/) | Record members, tickets and students coming in; a ticket admits once. | | [Reference data](https://objectsgrid.com/docs/guides/reference-data/) | Look up and search country, subdivision, language, currency, time zone, locale and unit codes, with names in every language; resolve the codes your objects store. Free and public. | --- Source: https://objectsgrid.com/docs/guides/authentication/ # Authentication Every ObjectsGrid request, GraphQL or REST, carries an **access token**: ```http Authorization: Bearer X-ObjectsGrid-AccessPoint: EU ``` The only requests without one are the token requests themselves, registering an Organization Account, and binding its administrator with a binding code. You get access tokens from the **token endpoint**, `POST https://apis.objectsgrid.com/oauth2/token`, which follows [OAuth 2.0](https://datatracker.ietf.org/doc/html/rfc6749). The `grant_type` depends on who is calling: | Who calls | Account | `grant_type` | Refresh token | |---|---|---|---| | A person using your app | [User Account](https://objectsgrid.com/docs/accounts/user-account/) | `urn:ietf:params:oauth:grant-type:token-exchange` | Yes | | Your servers and scripts | [Service Account](https://objectsgrid.com/docs/accounts/service-account/) of type `secret` | `client_credentials` | No | | A user account renewing its token | [User Account](https://objectsgrid.com/docs/accounts/user-account/) | `refresh_token` | Yes | | Anonymous visitors of your app | [Service Account](https://objectsgrid.com/docs/accounts/service-account/) of type `public` | none: a [public API key](#anonymous-access) | No | Send the parameters **form-encoded** (`application/x-www-form-urlencoded`), as OAuth 2.0 libraries do, or as a **JSON** object, with the `X-ObjectsGrid-AccessPoint` header of your Organization Account, as with every request: it picks the data center that holds your accounts. The answer is `200 OK`, with `Cache-Control: no-store`: ```json { "access_token": "", "token_type": "Bearer", "expires_in": 3599, "refresh_token": "" } ``` **Access tokens last one hour.** A change to an account's tags applies at its next token, and a disabled account gets no new token. Any OAuth 2.0 client library works, once it sends the `X-ObjectsGrid-AccessPoint` header. The endpoints are in the [OAuth metadata](https://objectsgrid.com/.well-known/oauth-authorization-server) (RFC 8414, issuer `https://objectsgrid.com`), and every parameter is in the [Tokens contract](https://objectsgrid.com/.well-known/openapi/Tokens/v1/openapi.yaml). In Go, for example: ```go config := clientcredentials.Config{ // golang.org/x/oauth2/clientcredentials ClientID: "", ClientSecret: "", TokenURL: "https://apis.objectsgrid.com/oauth2/token", } // the token requests carry the access point header ctx = context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: accessPoint{"EU"}}) client := config.Client(ctx) // gets and renews its access token itself ``` with a transport that adds the header: ```go type accessPoint struct{ name string } func (a accessPoint) RoundTrip(r *http.Request) (*http.Response, error) { r = r.Clone(r.Context()) r.Header.Set("X-ObjectsGrid-AccessPoint", a.name) return http.DefaultTransport.RoundTrip(r) } ``` ## Errors A refused token request answers an [OAuth 2.0 error](https://datatracker.ietf.org/doc/html/rfc6749#section-5.2): ```json {"error": "invalid_grant", "error_description": "The ID Token is not valid.", "correlationId": ""} ``` | `error` | Status | Meaning | |---|---|---| | `invalid_request` | 400 | A parameter is missing, repeated or malformed, or the `X-ObjectsGrid-AccessPoint` header is missing or isn't your Organization Account's | | `invalid_client` | 401 | Unknown client, wrong secret, or a disabled service account | | `invalid_grant` | 400 | The ID token or refresh token is expired, forged, revoked or issued to an app not in `identityProviders`, its nonce is wrong, its email isn't verified, or the sign-in is older than `refreshTokenLifetimeHours` | | `unauthorized_client` | 400 | `client_credentials` with a public service account, or a request from an origin its `allowedOrigins` doesn't list | | `unsupported_grant_type` | 400 | A `grant_type` not in the table above | The rate limit (`429`), the [spending cap](https://objectsgrid.com/docs/guides/usage-and-limits/) and server errors keep ObjectsGrid's [usual error](https://objectsgrid.com/docs/guides/errors-and-troubleshooting/). ## User accounts People sign in to your app with an [OpenID Connect](https://openid.net/developers/how-connect-works/) provider: [Google](https://objectsgrid.com/docs/get-started/login-with-google/), [Apple](https://objectsgrid.com/docs/get-started/sign-in-with-apple/), or your organization's own, such as your [Okta](https://objectsgrid.com/docs/get-started/sign-in-with-okta/) org. Your app receives an **ID token** and exchanges it for an access token. `client_id` is your Organization Account id, and `nonce`, optional, the nonce your app gave the provider for this sign-in: ```bash curl -X POST https://apis.objectsgrid.com/oauth2/token \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \ --data-urlencode 'subject_token=' \ -d subject_token_type=urn:ietf:params:oauth:token-type:id_token \ -d 'client_id=' \ -d 'nonce=' ``` - The User Account is created on the person's first sign-in. - The ID token must be issued to an app your Organization Account lists in `identityProviders`, or the request is refused with `invalid_grant`. See [Sign in with Google](https://objectsgrid.com/docs/get-started/login-with-google/#3-register-the-client-id-with-objectsgrid), [Sign in with Apple](https://objectsgrid.com/docs/get-started/sign-in-with-apple/#3-register-the-services-id-with-objectsgrid) and [Sign in with Okta](https://objectsgrid.com/docs/get-started/sign-in-with-okta/#3-register-your-okta-issuer-with-objectsgrid). - An ID token from Google or Apple that carries an email must have it verified (`email_verified`). One from an issuer of your own may leave `email_verified` out, as Okta does, but not say `false`. - A `nonce` sent with the ID token must be the token's own. Send one: it stops a token taken from another sign-in from being replayed. - The answer also has `"issued_token_type": "urn:ietf:params:oauth:token-type:access_token"` ([RFC 8693](https://datatracker.ietf.org/doc/html/rfc8693)). ## Two ways to sign in A User Account can sign in with more than one provider, such as Google, Apple and your Okta org. ObjectsGrid never joins accounts by email, so the person adds the second way to their own account: signed in with the first, they send the second provider's ID token with their access token. ```bash curl -X POST https://apis.objectsgrid.com/useraccounts//identities \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer " \ -d '{"idToken": "", "nonce": ""}' ``` - Only the account itself may, with its own access token: an administrator's is refused. - The ID token is checked as a sign-in checks it: issued to an app in `identityProviders`, its email verified, its nonce the one sent. - The answer is the User Account, with the sign-in among its `identities`. A sign-in that already opens another account is refused with `409`: delete that account first, which releases its sign-ins, then link. ## Service accounts Servers, scripts and scheduled jobs sign in with a [service account](https://objectsgrid.com/docs/accounts/service-account/) of type `secret`, using its id and secret with [HTTP Basic authentication](https://datatracker.ietf.org/doc/html/rfc7617): `Basic` followed by the Base64 encoding of `:`. ```bash curl -X POST https://apis.objectsgrid.com/oauth2/token \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -u ':' \ -d grant_type=client_credentials ``` Instead of HTTP Basic, you can send `client_id` and `client_secret` with the other parameters, but not both ways at once. A service account gets no refresh token: when its access token expires, it asks for a new one with the same credentials. To create a service account, an administrator sends `POST /serviceaccounts` with `{"type": "secret"}`. The response holds the generated `secret`. Rotate it with `POST /serviceaccounts/{id}/secret`; the old secret keeps working for 24 hours. See [Service account](https://objectsgrid.com/docs/accounts/service-account/). ## API keys An Organization Account created [without signing in](https://objectsgrid.com/docs/get-started/start-without-signing-in/), or with `"bootstrapPrincipals": true`, comes with three service accounts, admin, user and anonymous, and an **API key** for each, shown once in the create response. Send it like any access token. The admin and user keys work for 90 days; after that, those service accounts get access tokens as above. The anonymous key has no expiry: see below. Unlike an ordinary access token, an API key follows its service account: disabling or deleting the account stops it within a minute, and it carries the account's tags as they are now, not as they were when it was made. ## Anonymous access Visitors who haven't signed in, such as people browsing your product catalog, use a service account of type `public`. It has no secret, so there's nothing to sign in with: your web page or app sends the account's **public API key** as its access token, with no token request. An administrator makes the key: ```bash curl -X POST https://apis.objectsgrid.com/serviceaccounts//apikey \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $ADMIN_TOKEN" ``` ```json {"serviceAccountId": "", "apiKey": ""} ``` - **No expiry.** The key is public anyway: anyone can read it in your page. It works until you disable or delete its service account, which stops it within a minute. Every key you make for the account works the same way. - **Only what every visitor may see.** Give the public service account only that, through your [ABAC policy](https://objectsgrid.com/docs/guides/access-control/). - **Billed to you.** Its requests count against your Organization Account's usage. Two settings on the public service account limit what a copied key can do: | Field | What it does | |---|---| | `allowedOrigins` | The origins your pages are served from, such as `["https://shop.example.com"]`. A browser request from any other origin is refused with `403`, so other websites can't use your key from their visitors' browsers. Requests without an `Origin` header, from servers and scripts, aren't refused: this doesn't stop scripts. None listed: any origin | | `monthlyRequestLimit` | How many billable requests the key may make a month, under your [spending cap](https://objectsgrid.com/docs/guides/usage-and-limits/). Once made, its requests get `429` until the month ends, and your other keys keep working. `0` or absent: no limit of its own | `GET /serviceaccounts/{id}/usage` shows an administrator the key's requests this month, by origin: each allowed origin, `none` (no `Origin` header) and `unlisted` (browser requests of an account that lists no origins). If your app wants an access token instead, ask for one with the account's id alone: ```bash curl -X POST https://apis.objectsgrid.com/oauth2/token \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -d grant_type=urn:objectsgrid:params:oauth:grant-type:anonymous \ -d 'client_id=' ``` `client_credentials` refuses a public service account with `unauthorized_client`: OAuth 2.0 keeps it for clients that hold a secret (RFC 6749 section 4.4). ### When a public key is misused Someone copying your key can't be told apart from your visitors, so replace the key rather than only stopping it: 1. Create a new public service account with the same tags, such as `role` = `anonymous`. Your ABAC policy decides on tags, so the new key gets the same access. 2. Make its API key, ship it in your site or app, and deploy. 3. Disable or delete the old service account. Its key stops within a minute. Both keys work between steps 1 and 3, so your visitors see no gap. To stop the old key at once, do step 3 first: your pages fail until step 2. Old versions of a mobile app keep the old key until users update: the usage of the old account shows when its traffic has died down. ## Refreshing a user's access token A user's refresh token lasts three months, or less if your Organization Account sets how long a sign-in lasts. Use it to get a new access token before the old one expires, so the user doesn't have to sign in again: ```bash curl -X POST https://apis.objectsgrid.com/oauth2/token \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -d grant_type=refresh_token \ --data-urlencode 'refresh_token=' ``` - The refresh token alone authenticates the request: no access token is needed, so it also works after the access token has expired. - Each refresh token works **once**. The response holds a new access token and a new refresh token; keep the new one. - With `refreshTokenLifetimeHours` on your [Organization Account](https://objectsgrid.com/docs/accounts/organization-account/), from 1 to 2400, a sign-in lasts that many hours from when the person signed in, however often your app refreshes; then a refresh gets `invalid_grant` and the person signs in again. Without it, each refresh token lasts 100 days from when it was issued. See [How long a sign-in lasts](https://objectsgrid.com/docs/get-started/sign-in-with-okta/#how-long-a-sign-in-lasts). ## Revoking a refresh token If a refresh token is leaked or stolen, revoke it ([RFC 7009](https://datatracker.ietf.org/doc/html/rfc7009)), with an access token of the same Organization Account that your [ABAC policy](https://objectsgrid.com/docs/guides/access-control/) allows to (action `RevokeRefreshToken`): ```bash curl -X POST https://apis.objectsgrid.com/oauth2/token/revoke \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $ADMIN_TOKEN" \ --data-urlencode 'token=' ``` - The answer is `200`, also when the token was already revoked or isn't a valid token: nothing tells a caller which tokens exist. - `token_type_hint` is optional, and ignored: the token says what it is. - Access tokens and API keys can't be revoked (`unsupported_token_type`): an access token expires within the hour; disable the account (`disabled: true`) to stop it from getting new tokens and to stop its API keys at once. ## The first token endpoints Until 2026-11-23, each kind of account had its own endpoint, taking JSON only and answering `201` with ObjectsGrid's errors: `/oauth2/token/useraccount`, `/oauth2/token/serviceaccount`, `/oauth2/token/anonymous` and `/oauth2/token/refresh`. They still work, the same way, and will be removed once nothing calls them. Move to `/oauth2/token`: the same parameters work there. ## Good practice - Keep access tokens in memory, and refresh tokens and secrets in secure storage. Never put a service account secret in a browser or mobile app: a public API key is the only credential meant for them. - Refresh a few minutes before `expires_in` runs out, rather than waiting for a `401`. - Use a separate service account per job or server, with only the tags it needs, so you can rotate or disable one without touching the others. - Give each site or app its own public service account, with `allowedOrigins` and a `monthlyRequestLimit`, so a misused key is limited and replaced on its own. --- Source: https://objectsgrid.com/docs/guides/access-control/ # Access control with ABAC ObjectsGrid decides every request with your Organization Account's **ABAC policy**: attribute-based access control, where the attributes are the **tags** of the account making the request and the tags of the objects it touches. You write the policy in [Open Policy Agent Rego](https://www.openpolicyagent.org/docs/latest/policy-language/). For example, the rule *members of the marketing department may update brands tagged `department: marketing`* needs no role per brand and no list of users: tag the users and the brands, and one rule covers them all. If you are new to ABAC, read [Attribute Based Access Control](https://objectsgrid.com/blog/attribute-based-access-control/) and [ABAC vs RBAC](https://objectsgrid.com/blog/abac-vs-rbac/). ## Tags Accounts and objects carry **tags**, name and value pairs: ```json "tags": [ {"name": "department", "val": "marketing"}, {"name": "role", "val": "brand-manager"} ] ``` - A name may repeat (`role: buyer` and `role: approver`), so read a name as a set of values. The same name and value appear only once. - Names use lowercase letters, digits and `-`, in parts separated by `.`, such as `cost-center` or `acme.region`. Values are compared exactly, case included. - Names starting with `security.` are **security tags**: the platform defines them and who may write them, whatever your policy says. Any other `security.` name or value is refused. - Every account also has the tag `organization_account_id` with your Organization Account id. The platform sets it, and nobody can change or remove it. See [Tag](https://objectsgrid.com/docs/objects/tag/) for how tags behave on create, replace and patch. ## Administrators The tag `security.role` with the value `organization-account-administrator` makes a User Account or a `secret` Service Account an **administrator**. The policy isn't evaluated for administrators: they may do everything in their Organization Account. The person who registered the Organization Account is its first administrator. To protect your Organization Account from being locked out: - Only an administrator can grant or remove the role, or change, disable or delete an account that holds it. - An administrator can't remove their own role, or disable or delete their own account, so there is always one left. - A `public` service account can't be an administrator. - Only administrators can replace the ABAC policy, change `identityProviders`, `monthlyQuota` and `customerDataRetentionYears`, and revoke refresh tokens. ### Accounting and legal holds - **The accounting role:** `security.role` = `accounting` lets an account read what an erased person's Orders keep for accounting. Every other account, administrators included, reads those fields as hidden, whatever the policy says. See [Personal data and erasure](https://objectsgrid.com/docs/guides/personal-data/#what-orders-keep-for-accounting). - **The legal hold:** `security.legal-hold` = `true` on a Person stops its erasure. - **The erase action:** administrators can erase a Person. Let others with a rule on `input.action == "erase"`. - **Linking an account to a Person:** creating or changing a UserAccount so that its `person` points to a Person needs the right to `update` that Person, so the right to create accounts doesn't let anyone attach one to someone else's Person. The answer is 401 without it. Like the administrator role, only administrators can add or remove these tags. ## The default policy A new Organization Account starts with a policy that gives accounts other than administrators **no access**, and shows examples in comments. Read yours with `GET /abacpolicies/abac-policy--`. ```rego package abac import rego.v1 default allow := false ``` Add rules to it, then replace it with `PUT /abacpolicies/abac-policy--`, sending `{"policy": ""}`. A policy that doesn't compile, or isn't in `package abac`, is refused with `400` and the old one stays. ## How a request is decided Each request is decided in two stages, with the same policy: 1. **Operation stage.** May this account perform this action on this type at all? `input.object` is `null`. 2. **Object stage.** May it perform the action on this object? It runs once for each object the request reads or writes, with `input.object` set to the stored object. A `create` is decided at the operation stage, on the new object. A request is allowed when an `allow` rule holds and no `deny` rule holds, at both stages. In a list, objects the account may not read are left out. !!! warning "Let the operation stage through" A rule that only looks at `input.object` can't hold at the operation stage, where `input.object` is `null`, so the request is denied before any object is checked. Give such rules a companion rule for `input.object == null`, as in the examples below. ### The input | Field | What it holds | |---|---| | `input.subject` | The account making the request: `id`, `objectType` (`UserAccount` or `ServiceAccount`) and `tags`. | | `input.action` | `create`, `retrieve`, `list`, `update`, `patch`, `delete` or `retag`. | | `input.objectType` | The catalog name of the type the request addresses, such as `Product`, `Order`, `ABACPolicy`, `LogEvent`, or `Enum` for `/enums`. | | `input.object` | At the object stage, the stored object, every field the API returns except credentials. `null` at the operation stage and on create. Its own type is `input.object.meta.objectType`. | | `input.newObject` | For `create`, `update` and `patch`: the object as the write would leave it. | | `input.changedFields` | With `input.newObject`: the top-level fields the write changes. On create, every field the new object has. | The policy's own outputs are `allow`, `deny`, `redact` and `visible`. ## Examples A small helper keeps rules readable: ```rego has_tag(x, name, val) if { some t in x.tags t.name == name t.val == val } ``` ### Let everyone read the catalog Every signed-in account, and your anonymous visitors, may read products and offers: ```rego allow if { input.action in {"retrieve", "list"} input.objectType in {"Product", "Offer"} } ``` ### Department access Members of the marketing department may read and update brands of their department: ```rego allow if { input.action in {"retrieve", "list", "update", "patch"} input.objectType == "Brand" input.object == null # operation stage has_tag(input.subject, "department", "marketing") } allow if { input.action in {"retrieve", "list", "update", "patch"} input.objectType == "Brand" has_tag(input.subject, "department", "marketing") has_tag(input.object, "department", "marketing") # object stage } ``` ### Owners manage their own objects Each account may change and delete the reviews it created: ```rego allow if { input.action in {"update", "patch", "delete"} input.objectType == "Review" input.object == null } allow if { input.action in {"update", "patch", "delete"} input.objectType == "Review" input.object.meta.createdBy == input.subject.id } ``` ### Guard a field with deny A `deny` rule overrides every `allow` rule, so a guard is written once. Only brand managers rename brands: ```rego deny if { input.objectType == "Brand" "name" in input.changedFields not has_tag(input.subject, "role", "brand-manager") } ``` ## Changing tags: the retag action Tags decide access, so changing them is a separate permission. An `update` or `patch` that changes an object's tags is also decided as the action **`retag`**: allowing `update` doesn't allow changing tags. For example, marketing may move brands only between tags they hold themselves: ```rego allow if { input.action == "retag" input.objectType == "Brand" has_tag(input.object, "department", "marketing") has_tag(input.newObject, "department", "marketing") every t in input.newObject.tags { has_tag(input.subject, t.name, t.val) } } ``` A create isn't a retag: the tags a new object starts with are decided with the `create`, on `input.newObject`. ## Hiding fields A policy can hide fields from some readers: - `redact contains "" if { ... }` hides a field. - `visible contains "" if { ... }`, when the policy has any `visible` rules, shows only the fields they name. Paths reach nested fields and lists: `brand.url`, or `offers.price` for the price of every offer. Only buyers see what brands cost: ```rego redact contains "cost" if { input.objectType == "Brand" not has_tag(input.subject, "role", "buyer") } ``` Hidden fields are left out of every response: REST, GraphQL (where they read as `null`) and webhook deliveries. The object's `meta.redactedFields` lists them. An account can't set, change, filter or sort on a field hidden from it, and a `PUT` that leaves hidden fields out keeps them. `id`, `meta`, `at_type`, `at_context` (on Schema.org types) and `url` are always shown. ## Testing a policy A policy change can lock people out, or let them in. Test it before you rely on it: - Try changes in a separate Organization Account first. - Keep the previous policy, so you can put it back with one `PUT`. - Check the [access log](https://objectsgrid.com/docs/accounts/access-log-entry/): each entry shows which objects access was granted or denied to, and the version of the policy that decided. Need help with a policy? [Contact support](https://objectsgrid.com/docs/support/). --- Source: https://objectsgrid.com/docs/guides/graphql-api/ # 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 ` | | Playground | [apis.objectsgrid.com/playground](https://apis.objectsgrid.com/playground) | | Schema | [schema.graphql](https://objectsgrid.com/.well-known/graphql/schema.graphql), or introspection, which needs no token | Get an access token first; see [Authentication](https://objectsgrid.com/docs/guides/authentication/). The GraphQL API serves business objects. Accounts, policies, access logs and enums are managed with the [REST API](https://objectsgrid.com/docs/guides/rest-api/). ## Your first query ```bash 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 } } } }"}' ``` ```json { "data": { "products": { "items": [ { "id": "2b5f8f0e-1d0c-4d61-9a7e-5a1f0c3e9d21", "sku": "TRS-42", "name": [{ "at_language": "en", "at_value": "Trail Running Shoe" }] } ] } } } ``` In the [playground](https://apis.objectsgrid.com/playground), put the headers in the Headers panel: ```json { "X-ObjectsGrid-AccessPoint": "EU", "Authorization": "Bearer " } ``` ## 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](https://objectsgrid.com/docs/objects/) lists the operations of its type. ## Create, read, update and delete === "Create" ```graphql 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 } } } ``` === "Read" ```graphql 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 } } } ``` === "Update" ```graphql 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 } } } ``` === "Delete" ```graphql 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`](https://objectsgrid.com/docs/guides/rest-api/#replace-and-update). ## References A field that points to another object is typed `ObjectsGridObject`, the interface every object implements. Select the [Reference](https://objectsgrid.com/docs/objects/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. ```graphql 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: "" }`, 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](https://objectsgrid.com/docs/guides/json-ld/#from-graphql). ## Free slots `availableSlots` gives a provider's free times, for a booking page: the working hours of their [EmployeeRoles](https://objectsgrid.com/docs/objects/employee-role/) (`workSchedule`, [Schedules](https://objectsgrid.com/docs/objects/schedule/): 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. ```graphql 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](https://objectsgrid.com/docs/objects/language-tagged-string/). Select their subfields: ```graphql { 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`: ```graphql { 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 `GroupBy` for groups with counts and aggregates. [Lists](https://objectsgrid.com/docs/guides/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](https://objectsgrid.com/docs/guides/personal-data/)). 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: "", version: "1763025002419837")`. Earlier versions stay readable after the object is deleted, and they carry the object's current tags. See [the REST guide](https://objectsgrid.com/docs/guides/rest-api/#earlier-versions). `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: ```json { "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](https://objectsgrid.com/docs/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](#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](https://objectsgrid.com/docs/guides/errors-and-troubleshooting/). ## Logs Frontend log events are written with one mutation per batch and searched with a query; see [Frontend logging](https://objectsgrid.com/docs/guides/frontend-logging/#graphql). --- Source: https://objectsgrid.com/docs/guides/rest-api/ # REST API Each object type has its own REST API, such as `/products` or `/orders`, at the base URL `https://apis.objectsgrid.com`. The REST APIs also manage what GraphQL doesn't: accounts, the ABAC policy, access logs and enums. ## Requests Every request sends two headers: ```http X-ObjectsGrid-AccessPoint: EU Authorization: Bearer ``` - Request and response bodies are JSON: send `Content-Type: application/json`. - Optionally, send `X-ObjectsGrid-SessionID` with your app's session id. It is recorded with the request and returned in the response, so you can follow a user's session through your logs and ours. - Every response carries `X-ObjectsGrid-CorrelationID`, the request's id, the same as its trace id in `X-ObjectsGrid-Trace-Id`. Quote it when you contact support. Each API is described by an OpenAPI 3.1 contract, listed in the [contract index](https://objectsgrid.com/.well-known/openapi/index.json). Load a contract into your favorite tool, such as Postman or an OpenAPI client generator, to get every operation, parameter and schema. ## Operations Most object types offer the same operations. For products: | Operation | Request | Success | |---|---|---| | Create | `POST /products` | `201` with the object | | Create up to 100 at once | `POST /products/batch` | `201` with the objects | | List and search | `GET /products` | `200` with a list | | Retrieve | `GET /products/{id}` | `200` with the object | | Replace | `PUT /products/{id}` | `200` with the object | | Update some fields | `PATCH /products/{id}` | `200` with the object | | Delete | `DELETE /products/{id}` | `200` | Some types offer fewer: log events can't be changed or deleted, and access logs can only be listed. Each page of the [object reference](https://objectsgrid.com/docs/objects/) lists the operations of its type. ## Create ```bash curl -i -X POST https://apis.objectsgrid.com/products \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{"sku": "TRS-42", "name": [{"at_language": "en", "at_value": "Trail Running Shoe"}]}' ``` ObjectsGrid assigns the `id`, `url` and `meta`, validates the object against its [schema](https://objectsgrid.com/.well-known/objects-catalog/index.json) and answers `201` with the stored object. The `Location` header holds its path and the `ETag` header its version. An object that isn't valid is refused with `400`, and the error's `reasons` name the fields in error. Enums are the one exception to assigned ids: you choose an [Enum](https://objectsgrid.com/docs/objects/enum/)'s id. ## Retrieve ```bash curl https://apis.objectsgrid.com/products/ \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" ``` Add `?lang=de` to get localized fields in one language: each keeps only its values in that language, an exact tag (`de-AT`) before a primary language (`de`). A field with no value in that language is returned whole. Send `Accept: application/ld+json` to get the object as a Schema.org JSON-LD document for your web pages, with the objects it references and your own addresses: see [JSON-LD for your pages](https://objectsgrid.com/docs/guides/json-ld/). ### Poll without downloading Send the `ETag` you hold in `If-None-Match`: while the object is still at that version, the answer is `304 Not Modified`, with no body, and isn't billed. Apps poll their [configuration and feature flags](https://objectsgrid.com/docs/guides/configuration-and-feature-flags/) this way. ### Earlier versions Every write keeps the previous version. Add `?version=` to read one of them, with its `meta.objectVersion` and `ETag`: ```bash curl "https://apis.objectsgrid.com/products/?version=1763025002419837" \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" ``` Earlier versions stay readable after the object is deleted. An earlier version carries the object's current `tags`, so your [access control](https://objectsgrid.com/docs/guides/access-control/) decides on today's tags. A version the object never had is `404`. ## Replace and update - **`PUT`** replaces the object with the body you send. Fields you leave out are removed, with two exceptions: `tags` and fields hidden from you by the ABAC policy are kept. - **`PATCH`** changes only what you send, following [JSON Merge Patch (RFC 7396)](https://datatracker.ietf.org/doc/html/rfc7396): a field you send replaces the stored value, a field set to `null` is removed, and fields you leave out are unchanged. Send it as `Content-Type: application/json`. ```bash curl -X PATCH https://apis.objectsgrid.com/products/ \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{"color": "Green", "gtin13": null}' ``` `id` and `meta` can't be changed. ## Delete ```bash curl -X DELETE https://apis.objectsgrid.com/products/ \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" ``` A deleted object is no longer returned by retrieve or list. Delete only what your users asked to delete. ## Optimistic concurrency Every object has a version, `meta.objectVersion`, returned as the `ETag` header. To make sure you don't overwrite a change someone made since you read the object, send the ETag back in `If-Match` with `PUT`, `PATCH` or `DELETE`: ```bash curl -X PATCH https://apis.objectsgrid.com/products/ \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -H 'If-Match: "1763025002419837"' \ -d '{"color": "Green"}' ``` If the object changed since, the answer is `412 Precondition Failed` and nothing is written: read it again, reapply your change and retry. Without `If-Match`, ObjectsGrid still makes sure each write applies to the version your access was checked against. If the object changes in between, it checks again; `409 Conflict` means the object kept changing, and you can retry. ## List and search `GET /` answers a page of objects, `{"items": [...], "pageInfo": {"endCursor": ..., "hasNextPage": ...}}`, chosen with a `where`, ordered with an `orderBy`, and paged with `first` and `after`: ```bash curl -G https://apis.objectsgrid.com/products \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ --data-urlencode 'where={"sku": "TRS-42"}' \ --data-urlencode 'orderBy={"meta": {"createdAt": "desc"}}' \ -d first=20 ``` | Parameter | Meaning | |---|---| | `where` | The objects to list, as JSON: conditions on any field, combined with `AND`, `OR` and `NOT`. Without it, every object is listed. | | `orderBy` | The order, as JSON: `{"": "asc"}` or `"desc"`, or a list of up to 3. | | `first` | Number of objects, from `1` to `100`; `20` by default. | | `after` | The previous page's `pageInfo.endCursor`, for the next page. | | `count` | `true` adds `totalCount`, how many objects the where matches. | | `groupBy` | Groups instead of objects, with counts and aggregates. | | `lang` | A [BCP 47](https://www.rfc-editor.org/info/bcp47) language tag, as on retrieve. | [Lists](https://objectsgrid.com/docs/guides/lists/) has every condition, counting and grouping, and what your ABAC policy allows. The `query` parameter, an Elasticsearch Query DSL request, was removed: use `where` and `orderBy`. ## Batch create `POST //batch` creates up to 100 objects of one type in one request: ```bash curl -X POST https://apis.objectsgrid.com/products/batch \ -H 'Content-Type: application/json' \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ -d '{"items": [ {"sku": "TRS-41", "name": [{"at_language": "en", "at_value": "Trail Running Shoe 41"}]}, {"sku": "TRS-42", "name": [{"at_language": "en", "at_value": "Trail Running Shoe 42"}]} ]}' ``` - **All or nothing.** Every object is validated and authorized first. If any one isn't valid or allowed, nothing is created and the error's `reasons` name it by position, such as `/items/1/name`. - The `201` response holds `{"items": [...]}`, in the order of the request: each item has its `status`, `etag` and `object`. - Rarely, some objects can't be stored after the batch was accepted. The response is then `207`, each item with its own `status`, and an `error` for the failed ones; the others stay created. - Each object created counts as one request against your [monthly spending cap](https://objectsgrid.com/docs/guides/usage-and-limits/). Log events have their own batch request; see [Frontend logging](https://objectsgrid.com/docs/guides/frontend-logging/). ## References between objects A field that points to another object is a [Reference](https://objectsgrid.com/docs/objects/reference/): send `"brand": {"at_id": "https://apis.objectsgrid.com/brands/"}`, and it is stored and returned as `{"at_id": ..., "id": "", "at_type": "Brand"}`. An object of a type the field may not point to, or a URL of ObjectsGrid that names no object type, is refused with `400`, naming the field; a URL outside ObjectsGrid is kept as sent. The referenced object need not exist. See [The data model](https://objectsgrid.com/docs/guides/data-model/#references). REST returns references as they are stored. To read a referenced object, `GET` its `at_id`; to read several at once, list their type with `{"id": {"in": [...]}}`, or use [GraphQL](https://objectsgrid.com/docs/guides/graphql-api/#references), which reads them in the same request. Some references name one version of their target: an [Order](https://objectsgrid.com/docs/objects/order/)'s `customer` is stored with `at_id` `?version=`, the version that was newest when the Order was written. Send the plain URL, and the referenced object must exist. Sending back the stored value keeps it, and the plain URL again pins the newest version. Computed fields, such as a Product's `review`, are never sent: a write that holds one is refused with `400`, naming the field it is computed from. ## Errors Errors answer with an [ErrorResponse](https://objectsgrid.com/docs/objects/error-response/): ```json { "message": "The object is not valid", "reasons": ["/sku: required"], "httpStatusCode": 400, "httpStatusText": "Bad Request", "timestamp": 1763025002, "correlationId": "4bf92f3577b34da6a3ce929d0e0e4736" } ``` See [Errors and troubleshooting](https://objectsgrid.com/docs/guides/errors-and-troubleshooting/) for the status codes and what to do about each. --- Source: https://objectsgrid.com/docs/guides/data-model/ # The data model ObjectsGrid objects are modeled on [Schema.org](https://schema.org), the shared vocabulary that Google, Microsoft and others use to describe products, offers, organizations and places on the web. Where Schema.org has no fitting type, ObjectsGrid defines one in the same style. Each type is published as a JSON Schema (Draft 2020-12) in the [object catalog](https://objectsgrid.com/.well-known/objects-catalog/index.json), and documented in the [object reference](https://objectsgrid.com/docs/objects/). ## Why Schema.org - **Search engines understand it.** Your product pages can publish the same data as structured data, for rich results with prices, ratings and availability. - **Others understand it.** Marketplaces, partners, AI agents and tools already know `Product`, `Offer` and `PostalAddress`; less mapping, fewer misunderstandings. - **You don't have to invent it.** The common things, products, prices, opening hours, return policies, are already modeled with years of real-world use behind them. - **It lasts.** The vocabulary is maintained by a broad community and only grows. ## JSON-LD fields Schema.org data is usually written as [JSON-LD](https://json-ld.org), whose keywords start with `@`. ObjectsGrid spells them with `at_`, which every language and GraphQL can use as a field name: | ObjectsGrid | JSON-LD | Meaning | |---|---|---| | `at_context` | `@context` | The vocabulary, `https://schema.org`: only on Schema.org types, not on ObjectsGrid's own (GenericObject, JSONObject, AppConfiguration, FeatureFlag, Enum, LogEvent, Inventory) | | `at_type` | `@type` | The type, such as `Product` | | `at_value` | `@value` | A text value | | `at_language` | `@language` | The language of a text value | To publish an object as JSON-LD, for example in your product page, rename these fields and leave out the ObjectsGrid-only fields `tags` and `meta`. ## References Schema.org links objects rather than nesting them. A product doesn't contain its brand: its `brand` field is a [Reference](https://objectsgrid.com/docs/objects/reference/) to the brand, a JSON-LD node reference. ```json { "sku": "TRS-42", "brand": { "at_id": "https://apis.objectsgrid.com/brands/0f0b9a52-6d7e-4f4b-9d5e-3c1c2a7e8b11", "id": "0f0b9a52-6d7e-4f4b-9d5e-3c1c2a7e8b11", "at_type": "Brand" } } ``` - You send `{"at_id": ""}`; ObjectsGrid sets `id` and `at_type` from the URL. An object's URL is `https://apis.objectsgrid.com//`, also in its own `at_id` and `url` fields. - Each field names the types it may point to (a product's `brand` a Brand or an Organization); an object of another type is refused. A URL outside ObjectsGrid is accepted as it is, with the Schema.org `at_type` you send. - One brand can be referenced by many products, and is changed in one place. - To read the referenced object, read its `at_id`, with the same headers as any request. In GraphQL, select the object's fields in the same query: see [References](https://objectsgrid.com/docs/guides/graphql-api/#references). - A list that grows as other objects are created is never stored on the object: a product's `review` is computed from the [Reviews](https://objectsgrid.com/docs/objects/review/) whose `itemReviewed` points to the product. Write the Reviews; read the list in GraphQL, or list the Reviews by `itemReviewed`. Small values that only make sense inside their parent are **embedded** instead: a [PostalAddress](https://objectsgrid.com/docs/objects/postal-address/), [GeoCoordinates](https://objectsgrid.com/docs/objects/geo-coordinates/), a [QuantitativeValue](https://objectsgrid.com/docs/objects/quantitative-value/) such as a weight, an [AggregateRating](https://objectsgrid.com/docs/objects/aggregate-rating/). They have no id and no API of their own. ## Localized text Text meant for people, such as `name`, `description` or `slogan`, is a list with one [LanguageTaggedString](https://objectsgrid.com/docs/objects/language-tagged-string/) per language: ```json "name": [ {"at_language": "en", "at_value": "Trail Running Shoe"}, {"at_language": "de", "at_value": "Trailrunning-Schuh"} ] ``` Language tags follow [BCP 47](https://www.rfc-editor.org/info/bcp47): `en`, `de`, `de-AT`, `fr-CA`. The REST API's `lang` parameter returns only the values in one language. ## Enumerations Fields with a fixed set of values, such as availability or order status, take the Schema.org URL of the value: ```json "availability": ["https://schema.org/InStock"], "orderStatus": "https://schema.org/OrderProcessing" ``` Country codes ([ISO 3166-1 alpha-2](https://www.iso.org/iso-3166-country-codes.html), such as `DE`) and currency codes ([ISO 4217](https://www.iso.org/iso-4217-currency-codes.html), such as `EUR`) are plain codes. All lists are on the [Enumerations](https://objectsgrid.com/docs/objects/enumerations/) page. For value lists of your own, use an [Enum](https://objectsgrid.com/docs/objects/enum/). ## Typed values Where Schema.org lets a value be text, a number or a date, ObjectsGrid gives each kind its own field, so the type is always clear. A [PropertyValue](https://objectsgrid.com/docs/objects/property-value/) or [LocationFeatureSpecification](https://objectsgrid.com/docs/objects/location-feature-specification/) uses `valueText`, `valueNumber`, `valueBoolean`, `valueDateTime` or `valueReference`, rather than one `value` field. ## Singular names Schema.org names a property in the singular even when it holds a list: a product's `isRelatedTo` is a list of references, and an organization's `founder` a list of founders. The name reads as a relation, *product → review → Review*, and stays the same whatever the number of values. Check the [object reference](https://objectsgrid.com/docs/objects/) for whether a field is a list. ## hasX is a relation, not a boolean In Schema.org, `hasX` means *has a relation with X*: `hasMerchantReturnPolicy` points to a return policy, and `hasCertification` a list of certifications. They are not `true`/`false` flags. ## What ObjectsGrid adds Every stored object also has fields that aren't part of Schema.org: - **`id`**: the object's id, assigned by ObjectsGrid. - **`tags`**: name and value pairs that your [ABAC policy](https://objectsgrid.com/docs/guides/access-control/) decides on. See [Tag](https://objectsgrid.com/docs/objects/tag/). - **`meta`**: read-only [metadata](https://objectsgrid.com/docs/objects/object-meta/): the version, the type, and who created and last changed the object, and when. ## Objects that aren't in Schema.org yet Some objects that clients need aren't defined by Schema.org. ObjectsGrid creates them in the same style, together with clients; [Inventory](https://objectsgrid.com/docs/objects/inventory/) is one. To request a new object type or a change, use the [Improvement Requests form](https://objectsgrid.com/docs/support/). --- Source: https://objectsgrid.com/docs/guides/lists/ # Lists: filter, sort, page, count and group Every object type's list takes the same parameters, in REST (`GET /`) and in GraphQL (`` and `GroupBy`): a **where** to choose the objects, an **orderBy**, and **first** and **after** to page through them. You can also **count** the objects a where matches, and **group** them with counts and aggregates. The syntax follows [Prisma](https://www.prisma.io/docs/orm/reference/prisma-client-reference#filter-conditions-and-operators). Every field of a type can be filtered on, nested fields and lists included, and so can the fields every object holds: `id`, `url`, `at_type` and `meta` (`{"id": {"in": ["…", "…"]}}` lists those objects). New and changed objects are listed within a few seconds of the write. ## A page of objects === "REST" ```bash curl -G https://apis.objectsgrid.com/products \ -H 'X-ObjectsGrid-AccessPoint: EU' \ -H "Authorization: Bearer $TOKEN" \ --data-urlencode 'where={"color": "Blue", "offers": {"isEmpty": false}}' \ --data-urlencode 'orderBy={"meta": {"createdAt": "desc"}}' \ -d first=20 ``` ```json { "items": [{"id": "2b5f8f0e-…", "sku": "TRS-42", "color": "Blue"}], "pageInfo": {"endCursor": "eyJ…", "hasNextPage": true} } ``` === "GraphQL" ```graphql { products(where: {color: {equals: "Blue"}, offers: {isEmpty: false}}, orderBy: [{meta: {createdAt: desc}}], first: 20) { items { id sku color } pageInfo { endCursor hasNextPage } } } ``` For the next page, send the page's `endCursor` as `after`, with the same where and orderBy. `hasNextPage` tells whether another page follows. `first` is 1 to 100, 20 by default. ## where A where holds conditions on fields. All of them must hold; combine them with `AND`, `OR` and `NOT` (lists of wheres). | On | Conditions | |---|---| | A string | `equals`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `contains`, `startsWith`, `endsWith`, `not`; `mode: insensitive` ignores case | | A number or a date-time | `equals`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `not` | | A boolean | `equals`, `not` | | A list of values (`category`, `sameAs`) | `has`, `hasSome`, `hasEvery`, `isEmpty` | | An embedded object (`weight`, `aggregateRating`) | a where on its fields: `{"weight": {"value": {"gt": 1}}}` | | A list of objects (`name`, `offers` of an OfferCatalog, `tags`) | `some`, `every`, `none` (a where that one, every or no element meets), `isEmpty` | In REST, a bare value means `equals`: `{"sku": "TRS-42"}`. In GraphQL every condition is an object: `{sku: {equals: "TRS-42"}}`. Localized text, such as `name`, is a list of [LanguageTaggedStrings](https://objectsgrid.com/docs/objects/language-tagged-string/): a condition on one element holds for the same element's language, so this finds products named "Boot" in English, not those named "Boot" in German and something else in English: ```json {"name": {"some": {"at_value": "Boot", "at_language": "en"}}} ``` A [Reference](https://objectsgrid.com/docs/objects/reference/) to another object takes conditions on its own fields, `at_id`, `id` and `at_type`: `{"brand": {"id": {"equals": "0f0b9a52-…"}}}`. A reference pinned to a version (`…?version=`) matches its `at_id` without the version. A list of references takes `some`, `none` and `isEmpty`. In REST, `is` and `isNot` put conditions on the referenced object's own fields: `{"brand": {"is": {"name": {"some": {"at_value": {"equals": "Acme"}}}}}}` finds the products of the brands named Acme, and `{"orderItem": {"some": {"is": {"gtin13": {"equals": "4006381333931"}}}}}` the orders of a product. The condition may match at most 1,000 referenced objects. GraphQL filters on a reference's own fields only; read the referenced objects through the reference instead. A where holds at most 50 conditions, nested at most 5 levels. ## orderBy `{"": "asc"}` or `"desc"`, or a list of up to 3 of them. An embedded object's fields nest: `{"meta": {"createdAt": "desc"}}`. Lists can't be sorted on. The object's id always ends the order, so pages never overlap or skip an object. In REST, a field can also say where objects without it go: `{"": {"sort": "asc", "nulls": "last"}}` (`"first"` or `"last"`). GraphQL takes only `asc` or `desc`: `orderBy: [{meta: {createdAt: desc}}]`. ## Count === "REST" `count=true` adds `totalCount`, the number of objects the where matches: ```bash curl -G https://apis.objectsgrid.com/products … --data-urlencode 'where={"color": "Blue"}' -d count=true -d first=1 ``` === "GraphQL" Select `totalCount`: ```graphql { products(where: {color: {equals: "Blue"}}) { totalCount } } ``` ## Groups A groupBy groups the objects by 1 to 3 fields, and counts or aggregates each group: `_count`, `_sum`, `_avg`, `_min` and `_max` (sums and averages on numbers; minimum and maximum on numbers and date-times). `having` keeps the groups whose aggregates meet conditions (`equals`, `gt`, `gte`, `lt`, `lte`). === "REST" ```bash curl -G https://apis.objectsgrid.com/ratings … \ --data-urlencode 'groupBy={"by": ["reviewAspect"], "_count": true, "_avg": {"ratingValue": true}, "having": {"ratingValue": {"_avg": {"gte": 4}}}, "orderBy": {"reviewAspect": "asc"}}' ``` ```json { "groups": [{"reviewAspect": "comfort", "_count": 12, "_avg": {"ratingValue": 4.3}}], "pageInfo": {"endCursor": "", "hasNextPage": false} } ``` A groupBy holds its own `where`, `take` (1 to 100, 20 by default) and `cursor`; it isn't combined with the `where`, `orderBy`, `first`, `after` or `count` parameters. === "GraphQL" Select the counts and aggregates you want: ```graphql { ratingsGroupBy(by: [reviewAspect], having: {ratingValue: {_avg: {gte: 4}}}, orderBy: [{reviewAspect: asc}]) { groups { reviewAspect _count { _all } _avg { ratingValue } } pageInfo { endCursor hasNextPage } } } ``` Groups are ordered by their by fields or, when grouping by one field, by an aggregate (`{"_count": {"_all": "desc"}}`). ## Who may list what Your [ABAC policy](https://objectsgrid.com/docs/guides/access-control/) decides each listed object: a page holds only the objects you may read, so a page can hold fewer than `first` objects while `hasNextPage` is still true. And: - **A field hidden from you** can't be used in a where, an orderBy or a groupBy: the list is refused with `400` and the field's name. - **A count and a groupBy** cover objects without returning them, so they need access to every object of the type: a policy that decides on each object (by its tags, say) refuses them with `401`. List page by page instead. Administrators may always. ## Mistakes A where, orderBy or groupBy the type doesn't take is refused with `400`, naming the part that's wrong, such as `where.colour: unknown field` or `orderBy.sameAs: can't be sorted`. In GraphQL, the schema itself refuses an unknown field. `from` and `size` are gone: page with `first` and `after`. The `query` parameter (Elasticsearch Query DSL) was removed on 2026-11-20 and is refused with `400`: use `where` and `orderBy`. --- Source: https://objectsgrid.com/docs/guides/json-ld/ # JSON-LD for your pages Ask for an object as `application/ld+json` and ObjectsGrid answers a finished [Schema.org](https://schema.org/) JSON-LD document: the object's fields, the objects it references, and every address on your own domain. Put it in your page as ` ``` Search engines read it from the HTML. A page can also fetch it in the browser with a [public API key](https://objectsgrid.com/docs/guides/authentication/#anonymous-access) that its [access policy](https://objectsgrid.com/docs/guides/access-control/) lets read these types; search engines that run your page's JavaScript read that too, but HTML is read by more of them. ## From GraphQL The types with a document have a `jsonLd` field, the same document as the REST read, so a page gets its data and its markup in one request: ```graphql query { product(id: "p-123") { name { at_value } jsonLd(lang: "en") } } ``` - `jsonLd` is a `JSON` value: write `JSON.stringify(data.product.jsonLd)` into the `