{
	"openapi": "3.0.1",
	"info": {
		"title": "Workspace API",
		"description": "Read one workspace from your own server, with an API key of that workspace.",
		"version": "1.0.0"
	},
	"servers": [
		{
			"url": "https://api.distito.com/workspace-v2"
		}
	],
	"paths": {
		"/workspace": {
			"get": {
				"operationId": "getWorkspace",
				"summary": "Get the workspace",
				"description": "Returns the workspace that the API key belongs to: its name, the number of its members and the largest number of members that it can have.",
				"parameters": [
					{
						"name": "X-Researcher-Id",
						"in": "header",
						"required": false,
						"description": "Optional. An identifier of your own for the person that the call acts for. Distito stores it as `api:<identifier>` on what the call creates, and shows it as the name of the creator. A call that only reads ignores it.",
						"schema": {
							"type": "string"
						}
					}
				],
				"security": [
					{
						"api_key": []
					}
				],
				"responses": {
					"200": {
						"description": "The workspace",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/Workspace"
								}
							}
						}
					},
					"403": {
						"description": "The request names no member of the workspace",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/Error"
								}
							}
						}
					}
				},
				"x-codeSamples": [
					{
						"lang": "Shell",
						"label": "curl",
						"source": "#!/bin/sh\nset -eu\n\n: \"${DISTITO_API_URL:?is not set}\"\n: \"${DISTITO_API_KEY:?is not set}\"\n\ncurl --fail-with-body --silent --show-error \\\n\t--header \"x-api-key: $DISTITO_API_KEY\" \\\n\t\"$DISTITO_API_URL/workspace\"\n"
					},
					{
						"lang": "JavaScript",
						"label": "Node.js",
						"source": "const required = function (name) {\n\t\tconst value = process.env[name];\n\t\tif (!value) {\n\t\t\tconsole.error(`${name} is not set`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\treturn value;\n\t},\n\tapiUrl = required('DISTITO_API_URL'),\n\tapiKey = required('DISTITO_API_KEY'),\n\tresponse = await fetch(`${apiUrl}/workspace`, {\n\t\theaders: { 'x-api-key': apiKey }\n\t}),\n\tbody = await response.text();\nconsole.log(body);\nif (response.status >= 400) {\n\tprocess.exitCode = 1;\n}\n"
					},
					{
						"lang": "Python",
						"label": "Python",
						"source": "import os\nimport sys\nimport urllib.error\nimport urllib.request\n\n\ndef required(name):\n    value = os.environ.get(name)\n    if not value:\n        sys.exit(f\"{name} is not set\")\n    return value\n\n\napi_url = required(\"DISTITO_API_URL\")\napi_key = required(\"DISTITO_API_KEY\")\n\nrequest = urllib.request.Request(\n    f\"{api_url}/workspace\",\n    headers={\"x-api-key\": api_key},\n)\ntry:\n    with urllib.request.urlopen(request) as response:\n        print(response.read().decode())\nexcept urllib.error.HTTPError as error:\n    print(error.read().decode())\n    sys.exit(1)\n"
					}
				]
			}
		}
	},
	"components": {
		"schemas": {
			"Workspace": {
				"type": "object",
				"description": "A workspace holds the members of one organisation and everything that they publish. Each API key belongs to one workspace.",
				"required": [
					"tenantId"
				],
				"properties": {
					"tenantId": {
						"type": "string",
						"description": "The identifier of the workspace."
					},
					"displayName": {
						"type": "string",
						"description": "The name of the workspace, as its members see it in the web app."
					},
					"memberCount": {
						"type": "integer",
						"description": "The number of members of the workspace, invited members included."
					},
					"maxMembers": {
						"type": "integer",
						"description": "The largest number of members that the workspace can have."
					}
				}
			},
			"Error": {
				"type": "object",
				"required": [
					"message",
					"error"
				],
				"properties": {
					"message": {
						"type": "string"
					},
					"error": {
						"type": "string"
					},
					"details": {
						"type": "object"
					},
					"requestId": {
						"type": "string"
					}
				}
			}
		},
		"securitySchemes": {
			"api_key": {
				"type": "apiKey",
				"name": "x-api-key",
				"in": "header",
				"description": "Send the key from a server, or from a dashboard that only the staff of your workspace open. Never put the key in a page that readers load: anybody who can read the page can use the key to act as your workspace."
			}
		}
	}
}
