{
  "openapi": "3.1.0",
  "info": {
    "title": "Organization Accounts REST API",
    "description": "API for managing organization accounts",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://apis.objectsgrid.com"
    }
  ],
  "paths": {
    "/organizationaccounts": {
      "post": {
        "summary": "Create a new organization account",
        "operationId": "createOrganizationAccount",
        "description": "With a Google or Apple ID token (Authorization: Bearer <ID token>), the person who signed in becomes the organization\naccount's first administrator, and the response's Authorization header holds their access token. Send\nbootstrapPrincipals: true to also get the bootstrap service accounts and API keys.\n\nWithout an Authorization header, anyone may create one, a person or an AI agent (zero-friction onboarding): it\nis unverified, held to 50,000 requests a month, and comes with an ABAC policy that gives each bootstrap service\naccount its role, the bootstrap service accounts and their API keys in the response's bootstrap field, and a\nbindingUrl. An administrator who signs in with Google or Apple there, or binds with the admin API key\n(POST /organizationaccounts/{orgacctid}/administrator), verifies it. Creation without a token is limited per\nclient address and per day (429). The API keys and the binding link are shown only in this response; with an\nemail, the binding link (never an API key) is also emailed to it, at most once a day per address.\n",
        "security": [
          {
            "idTokenAuth": [

            ]
          },
          {}
        ],
        "parameters": [
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU for European Union, or US for United States, depending on where you need to locate your data",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrganizationAccountCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successfully created the organization account, with its bootstrap service accounts and API keys when there are any",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrganizationAccountCreated"
                }
              }
            }
          },
          "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",
            "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"
                }
              }
            }
          }
        }
      }
    },
    "/organizationaccounts/{orgacctid}": {
      "get": {
        "summary": "Get an organization account",
        "operationId": "getOrganizationAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "orgacctid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the organization account to retrieve"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU for European Union, or US for United States, depending on where your data is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved the organization account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/OrganizationAccount/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": "Organization account 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 an organization account",
        "operationId": "updateOrganizationAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "orgacctid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the organization account to update"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU for European Union, or US for United States, depending on where your data 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/OrganizationAccount/v1/schema.json"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully updated the organization account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/OrganizationAccount/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": "Organization account 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: the spending cap, or other requests changing the organization account at the same moment (Cloud Storage takes about one write a second to it); try again in a few seconds",
            "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 an organization account",
        "operationId": "deleteOrganizationAccount",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "orgacctid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the organization account to delete"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU for European Union, or US for United States, depending on where your data 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 organization account"
          },
          "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": "Organization account 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: the spending cap, or other requests changing the organization account at the same moment (Cloud Storage takes about one write a second to it); try again in a few seconds",
            "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"
                }
              }
            }
          }
        }
      }
    },
    "/organizationaccounts/{orgacctid}/usage": {
      "get": {
        "summary": "Get an organization account's usage",
        "operationId": "getOrganizationAccountUsage",
        "description": "This month's billable requests so far against the spending cap, and each past month's billed figure. Only the\norganization account's own administrators can read it. It is never refused by the spending cap, so an\nadministrator can always see where the account stands.\n",
        "security": [
          {
            "accessTokenAuth": [

            ]
          }
        ],
        "parameters": [
          {
            "name": "orgacctid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the organization account"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU for European Union, or US for United States, depending on where your data is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "The organization account's usage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/OrganizationAccountUsage/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized, or not an administrator of the organization account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "404": {
            "description": "Organization account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests (the rate limit)",
            "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"
                }
              }
            }
          }
        }
      }
    },
    "/organizationaccounts/{orgacctid}/administrator": {
      "post": {
        "summary": "Bind an administrator to an unverified organization account",
        "operationId": "bindOrganizationAccountAdministrator",
        "description": "The person a Google or Apple ID token signs in as becomes an administrator of an organization account created without\nan ID token, which is then verified: its 50,000 requests a month limit is lifted, and the app the ID token was\nissued to is added to identityProviders. Authorize it with an administrator's access token of that organization\naccount, such as the admin API key, or, without an Authorization header, with the bindingCode of the bindingUrl\n(valid once, for 30 days). Everything the organization account holds is kept. Once it is verified, this\noperation answers 409, for good.\n",
        "security": [
          {
            "accessTokenAuth": [

            ]
          },
          {}
        ],
        "parameters": [
          {
            "name": "orgacctid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "ID of the organization account"
          },
          {
            "in": "header",
            "name": "X-ObjectsGrid-AccessPoint",
            "description": "EU for European Union, or US for United States, depending on where your data is located",
            "schema": {
              "type": "string",
              "enum": [
                "EU",
                "US"
              ]
            },
            "required": true
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BindAdministratorRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The administrator's user account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/UserAccount/v1/schema.json"
                }
              }
            }
          },
          "400": {
            "description": "Bad request, such as no idToken",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "401": {
            "description": "Not an administrator of the organization account, an invalid or used binding code, or an invalid ID token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "404": {
            "description": "Organization account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ErrorResponse/v1/schema.json"
                }
              }
            }
          },
          "409": {
            "description": "The organization account is verified already, or another binding is running",
            "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": {
      "OrganizationAccountCreateRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "countryCode": {
            "type": "string"
          },
          "commerceCode": {
            "type": "string"
          },
          "monthlyQuota": {
            "type": "integer"
          },
          "tags": {
            "type": "array",
            "items": {
              "$ref": "https://objectsgrid.com/.well-known/objects-catalog/Tag/v1/schema.json"
            }
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "Without an ID token only, optional. The creator's email, the organization account's billing contact; the binding link is emailed to it. Never an API key."
          },
          "bootstrapPrincipals": {
            "type": "boolean",
            "description": "Create the admin, user and anonymous service accounts and their API keys. Always without an ID token; false by default with one."
          },
          "nonce": {
            "type": "string",
            "description": "With an ID token only. The nonce your app gave the identity provider for this sign-in. Optional; when sent, the ID token's nonce must equal it, or the request is refused with 401."
          }
        },
        "required": [
          "name"
        ]
      },
      "OrganizationAccountCreated": {
        "description": "The created organization account, with bootstrap when it was created with bootstrap principals. bootstrap is in this response only, never in a later read.",
        "allOf": [
          {
            "$ref": "https://objectsgrid.com/.well-known/objects-catalog/OrganizationAccount/v1/schema.json"
          },
          {
            "type": "object",
            "properties": {
              "bootstrap": {
                "$ref": "#/components/schemas/Bootstrap"
              }
            }
          }
        ]
      },
      "Bootstrap": {
        "type": "object",
        "description": "The bootstrap service accounts and their API keys, shown once. admin holds the administrator role; user (tag role=user) reads and writes every business object, but not the webhook configuration or the accounts, policy and access logs; anonymous (tag role=anonymous) reads the catalog types and creates log events. The ABAC policy decides, and an administrator can change it.",
        "properties": {
          "admin": {
            "$ref": "#/components/schemas/BootstrapPrincipal"
          },
          "user": {
            "$ref": "#/components/schemas/BootstrapPrincipal"
          },
          "anonymous": {
            "$ref": "#/components/schemas/BootstrapPrincipal"
          },
          "bindingUrl": {
            "type": "string",
            "format": "uri",
            "description": "Unverified organization accounts only. The page where an administrator signs in with Google or Apple to bind and verify it; works once, for 30 days."
          },
          "notice": {
            "type": "string",
            "description": "How to use the API keys, in words."
          }
        },
        "required": [
          "admin",
          "user",
          "anonymous",
          "notice"
        ]
      },
      "BootstrapPrincipal": {
        "type": "object",
        "properties": {
          "serviceAccount": {
            "type": "object",
            "description": "The service account. A secret one comes with its secret, to get access tokens with POST /oauth2/token (client_credentials) once the API key has expired; the anonymous one has no secret, and its API key does not expire.",
            "properties": {
              "id": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "secret",
                  "public"
                ]
              },
              "description": {
                "type": "string"
              },
              "secret": {
                "type": "string"
              },
              "tags": {
                "type": "array",
                "items": {
                  "$ref": "https://objectsgrid.com/.well-known/objects-catalog/Tag/v1/schema.json"
                }
              }
            },
            "required": [
              "id",
              "type",
              "tags"
            ]
          },
          "accessToken": {
            "type": "string",
            "description": "The API key: an access token that works until expiresAt, 90 days, or, for the anonymous one, without expiry. Send it as Authorization: Bearer <accessToken>, with X-ObjectsGrid-AccessPoint. Disabling or deleting the service account stops it within a minute, and it carries the account's tags as they are now."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "When the API key stops working; absent for the anonymous one, which has no expiry"
          }
        },
        "required": [
          "serviceAccount",
          "accessToken"
        ]
      },
      "BindAdministratorRequest": {
        "type": "object",
        "properties": {
          "idToken": {
            "type": "string",
            "description": "A Google or Apple ID token of the person who becomes the administrator. Its email must be verified and not used by another account of the organization account."
          },
          "bindingCode": {
            "type": "string",
            "description": "Without an Authorization header, the bindingCode of the bindingUrl."
          },
          "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, or the request is refused with 401."
          }
        },
        "required": [
          "idToken"
        ]
      }
    },
    "securitySchemes": {
      "idTokenAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT ID Token obtain from the Identity Provider Google, Apple, etc."
      },
      "accessTokenAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "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."
      }
    }
  }
}
