{
  "openapi": "3.1.0",
  "info": {
    "title": "User Accounts REST API",
    "description": "API for managing User Accounts",
    "version": "v1"
  },
  "servers": [
    {
      "url": "https://apis.objectsgrid.com"
    }
  ],
  "paths": {
    "/useraccounts": {
      "post": {
        "summary": "Create User Account",
        "operationId": "createUserAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserAccountInfo"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successfully created the user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "The object version. Send it in the If-Match header to update, patch or delete this exact version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "409": {
            "description": "Conflict, the user account already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Query User Accounts",
        "operationId": "queryUserAccounts",
        "description": "This operation supports two valid combinations of input parameters. You can use only one of the following combinations at the time:\n  - query + from + size – Retrieves a paginated list of User Accounts based on a search query. The accounts of a Person: `{\"query\": {\"term\": {\"person.keyword\": \"<Person url>\"}}}`; find the Person by email with `GET /persons?email=`.\n  - iss + sub – Retrieves a User Account using the iss (Issuer) and sub (Subject) public claims from an ID Token.\n\nDue to OpenAPI's specification current limitations, these combinations cannot be split into separate operations. As a result, they are documented here under a single operation. This may increase the risk of incorrect parameter usage and unexpected behavior.\n",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          },
          {
            "in": "query",
            "name": "query",
            "schema": {
              "type": "string"
            },
            "description": "Elastic Search Query DSL for querying User Accounts. Used alongside the 'from' and 'size' parameters, and should not be combined with any others.",
            "example": "{ \"query\": { \"match_all\": {} } }"
          },
          {
            "in": "query",
            "name": "from",
            "schema": {
              "type": "integer"
            },
            "description": "Defines the starting record number for retrieval. Used in conjunction with the 'query' and 'size' parameters, and should not be combined with any others."
          },
          {
            "in": "query",
            "name": "size",
            "schema": {
              "type": "integer"
            },
            "description": "Defines the number of records to retrieve. Used in conjunction with the 'query' and 'from' parameters, and should not be combined with any others."
          },
          {
            "in": "query",
            "name": "iss",
            "schema": {
              "type": "string"
            },
            "description": "Retrieves a User Account using the 'iss' (Issuer) public claim attribute and the 'sub' (Subject) parameter from the ID Token issued by your Identity Provider (e.g., Google, Facebook, Okta). Must be used with the 'sub' parameter and no others."
          },
          {
            "in": "query",
            "name": "sub",
            "schema": {
              "type": "string"
            },
            "description": "Retrieves a User Account using the 'sub' (Subject) public claim attribute and the 'iss' (Issuer) parameter from the ID Token issued by your Identity Provider (e.g., Google, Facebook, Okta). Must be used with the 'iss' parameter and no others."
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully listed the user accounts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      }
    },
    "/useraccounts/{id}": {
      "get": {
        "summary": "Retrieve User Account",
        "operationId": "retrieveUserAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the user account to retrieve"
          },
          {
            "in": "header",
            "name": "If-None-Match",
            "description": "The ETag of the version you hold: answered 304 Not Modified, with no body and not billed, when the object is still at it. Poll a configuration or flags this way.\n",
            "schema": {
              "type": "string"
            },
            "required": false
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved the user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "The object version. Send it in the If-Match header to update, patch or delete this exact version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "304": {
            "description": "Not Modified, the object is still at the version If-None-Match named; no body, not billed"
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Update User Account",
        "operationId": "updateUserAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the user account to update"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          },
          {
            "in": "header",
            "name": "If-Match",
            "description": "The ETag of the object version being modified, as returned by the Retrieve, Create, Update or Patch operations.\nIf the object has been modified since that version, the request fails with 412 Precondition Failed.\n",
            "schema": {
              "type": "string"
            },
            "required": false
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully updated the user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "The object version. Send it in the If-Match header to update, patch or delete this exact version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "412": {
            "description": "Precondition Failed - the object was modified since the version in the If-Match header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Patch User Account",
        "operationId": "patchUserAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the user account to patch"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          },
          {
            "in": "header",
            "name": "If-Match",
            "description": "The ETag of the object version being modified, as returned by the Retrieve, Create, Update or Patch operations.\nIf the object has been modified since that version, the request fails with 412 Precondition Failed.\n",
            "schema": {
              "type": "string"
            },
            "required": false
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully updated the user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "The object version. Send it in the If-Match header to update, patch or delete this exact version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "412": {
            "description": "Precondition Failed - the object was modified since the version in the If-Match header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete User Account",
        "operationId": "deleteUserAccount",
        "description": "Deletes the User Account. Its Person stays; erase the Person (POST /persons/{id}/erasure) to remove the personal data. Its sign-ins are released: signing in with one of them again creates a new user account, or it can be linked to another (POST /useraccounts/{id}/identities). It cannot be undone; please use caution.",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the user account to delete"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          },
          {
            "in": "header",
            "name": "If-Match",
            "description": "The ETag of the object version being modified, as returned by the Retrieve, Create, Update or Patch operations.\nIf the object has been modified since that version, the request fails with 412 Precondition Failed.\n",
            "schema": {
              "type": "string"
            },
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully deleted the user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "412": {
            "description": "Precondition Failed - the object was modified since the version in the If-Match header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      }
    },
    "/useraccounts/{id}/identities": {
      "post": {
        "summary": "Add a way to sign in to your user account",
        "operationId": "linkUserAccountIdentity",
        "description": "Adds a second sign-in identity to your own user account, such as Sign in with Apple next to Google: send an ID\ntoken of the other provider with your access token, and either sign-in opens this account from then on. Only\nthe account itself may, with its own access token; nothing is merged on email, and the account's Person stays\nas it is. The ID token is checked as a sign-in checks it: valid, issued to an app the organization account lists\nin identityProviders, its email (when it carries one) verified, and its nonce equal to the one sent. An identity\nthe account holds already changes nothing; one another account of the organization account holds is refused\nwith 409.\n",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of your user account, the sub of your access token"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU or US depending on where your Organization Account is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LinkIdentityRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The user account, with the identity among its identities",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            }
          },
          "400": {
            "description": "Bad request: no idToken",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized: not the account itself, an invalid ID token, an app the organization account does not list, an unverified email, a nonce that differs, or a disabled account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "409": {
            "description": "Conflict: the identity signs in to another user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "UserAccountInfo": {
        "type": "object",
        "description": "A new User Account. Its personal data lives in its Person, created first with POST /persons. The account links to it and keeps the sign-in identity.",
        "properties": {
          "person": {
            "type": "string",
            "format": "uri",
            "description": "The url of the account's Person."
          },
          "iss": {
            "type": "string",
            "description": "The identity provider issuer. Can be found in the ID Token public claims"
          },
          "sub": {
            "type": "string",
            "description": "The identity provider subject. Can be found in the ID Token public claims"
          },
          "meta": {
            "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ObjectMeta/v1/schema.json"
          }
        },
        "required": [
          "person",
          "iss",
          "sub"
        ]
      },
      "LinkIdentityRequest": {
        "type": "object",
        "properties": {
          "idToken": {
            "type": "string",
            "description": "An ID token of the sign-in to add, from Google, Apple or one of the organization account's own issuers (such as its Okta org), issued to an app the organization account lists in identityProviders"
          },
          "nonce": {
            "type": "string",
            "description": "The nonce your app gave the identity provider for this sign-in. Optional; when sent, the ID token's nonce must equal it."
          }
        },
        "required": [
          "idToken"
        ]
      },
      "UserAccounts": {
        "type": "array",
        "items": {
          "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
        }
      }
    },
    "securitySchemes": {
      "accessTokenAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Bearer JWT",
        "description": "An ObjectsGrid access token (a JWT), sent as 'Authorization: Bearer <token>': from POST /oauth2/token, valid 1 hour, or an API key: a service account's from the bootstrap of an Organization Account created without signing in, valid 90 days; a public service account's (POST /serviceaccounts/{id}/apikey, or the bootstrap's anonymous one), without expiry, until its account is disabled or deleted."
      }
    }
  }
}
