Configurations
A configuration is a JSON document that sets up the Vidi map client: which layers, extensions and brand settings a map starts with. The Configurations API stores these documents in GC2 (Geo Compute Cloud), so a map can be pointed at a URL instead of a file on a server. Configurations are managed with a token, and the published ones are readable without a token, which is how Vidi loads them.
The API works on the same configurations as the Dashboard: one made there can be edited through the API and the other way round.
Access model:
- The database owner lists, creates, updates and deletes configurations. All management requests require an
Authorization: Bearerheader. - A sub-user cannot manage configurations — every management request is answered with
403(SUPER_USER_ONLY). - Anyone can read a configuration that has
publishedset totrue, without credentials. An unpublished configuration answers404on the token-less route, exactly like one that does not exist.
The configuration object
{
"key": "configuration_my_map_673211a0b1c2d312345678",
"name": "My map",
"description": "Configuration for the public map",
"published": true,
"body": "{\"brandName\": \"My map\"}"
}
Two rules apply to every request:
bodyis JSON text, not a JSON object. Send the Vidi configuration as a string (JSON.stringify(config)) and parse it yourself when you read it. The text must parse to a JSON object or array — a scalar or broken JSON is rejected with400(INVALID_REQUEST). It is stored and returned unchanged.keyis generated by the server in the formconfiguration_<name>_<id>. It is never accepted in a request body, and it does not change when the configuration is renamed.
Keys match ^configuration_[A-Za-z0-9_@+\-]+$. Keys generated by this API only use letters, digits and _, but keys made in the Dashboard can contain @, + and -, so URL-encode a key before putting it in a path (+ must be sent as %2B). Where a route takes several keys, encode each key and join them with a literal comma.
List configurations
GET without a key returns all configurations of the database, published or not, as a JSON array:
- Web App
- HTTP
GET https://api.gc2.io/api/v4/configurations HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
[
{
"key": "configuration_my_map_673211a0b1c2d312345678",
"name": "My map",
"description": "Configuration for the public map",
"published": true,
"body": "{\"brandName\": \"My map\"}"
},
{
"key": "configuration_draft_map_6732120fa4b5c698765432",
"name": "Draft map",
"description": "",
"published": false,
"body": "{\"brandName\": \"Draft\"}"
}
]
Get a configuration
GET with a key returns that configuration as an object. With several comma-separated keys the response is an array. If any of the keys does not exist, the response is 404 (CONFIGURATION_NOT_FOUND):
- Web App
- HTTP
GET https://api.gc2.io/api/v4/configurations/configuration_my_map_673211a0b1c2d312345678 HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
{
"key": "configuration_my_map_673211a0b1c2d312345678",
"name": "My map",
"description": "Configuration for the public map",
"published": true,
"body": "{\"brandName\": \"My map\"}"
}
Create a configuration
POST creates a configuration. name, description, published and body are all required: name must not be empty, description may be an empty string, and null is not accepted in any field. The response is 201 Created with an empty body and a Location header that carries the generated key — read the key from it:
- Web App
- HTTP
POST https://api.gc2.io/api/v4/configurations HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"name": "My map",
"description": "Configuration for the public map",
"published": true,
"body": "{\"brandName\": \"My map\"}"
}
HTTP/1.1 201 Created
Location: /api/v4/configurations/configuration_my_map_673211a0b1c2d312345678
The body may also be an array of configuration objects. They are created in one transaction, so one bad element creates nothing, and the Location header then holds all the keys, comma-separated.
A missing or unknown field — key included — is rejected with 400 (INPUT_VALIDATION_ERROR).
Update a configuration
PATCH is partial: send any non-empty subset of name, description, published and body. It takes a single key. The response is 303 See Other with a Location header pointing back to the configuration — follow it with a GET to see the updated state:
- Web App
- HTTP
PATCH https://api.gc2.io/api/v4/configurations/configuration_my_map_673211a0b1c2d312345678 HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"published": false
}
PATCH https://api.gc2.io/api/v4/configurations/configuration_my_map_673211a0b1c2d312345678 HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"body": "{\"brandName\": \"My map\", \"baseLayers\": []}"
}
body is replaced as a whole — there is no merging of the JSON inside it. Renaming a configuration does not change its key, so URLs that are already handed out keep working.
Delete a configuration
DELETE removes one or more configurations (comma-separated keys) and returns 204 No Content. Every key is checked first: if one of them does not exist, the response is 404 (CONFIGURATION_NOT_FOUND) and nothing is deleted:
- Web App
- HTTP
DELETE https://api.gc2.io/api/v4/configurations/configuration_my_map_673211a0b1c2d312345678 HTTP/1.1
Authorization: Bearer abc123
Without a token
Published configurations are read from a route that names the database in the path. It takes no credentials, and a token that is sent along is not looked at.
GET without a key lists the published configurations of the database:
GET https://api.gc2.io/api/v4/configurations/database/mydb HTTP/1.1
Accept: application/json; charset=utf-8
[
{
"key": "configuration_my_map_673211a0b1c2d312345678",
"name": "My map",
"description": "Configuration for the public map",
"published": true,
"body": "{\"brandName\": \"My map\"}"
}
]
GET with a key returns the configuration object, if it is published. The route takes one key, not a comma-separated list:
GET https://api.gc2.io/api/v4/configurations/database/mydb/configuration_my_map_673211a0b1c2d312345678 HTTP/1.1
Accept: application/json; charset=utf-8
The .json form
Append .json to the key to get the body itself, served as application/json (as a file attachment named after the key). This is the URL to give Vidi — Vidi expects the configuration document, not the object that wraps it:
GET https://api.gc2.io/api/v4/configurations/database/mydb/configuration_my_map_673211a0b1c2d312345678.json HTTP/1.1
{"brandName": "My map"}
An unpublished configuration and an unknown key both answer 404 (CONFIGURATION_NOT_FOUND), so keys cannot be probed. An unknown database answers 404 (DATABASE_NOT_FOUND).
published: false hides a configuration from the token-less route of this API. It does not make the configuration secret: configurations are stored in the key/value store under their configuration_* keys, where the users of the database, sub-users included, can read them. Do not put credentials in a configuration.
Do not create or edit configurations through the Key/value API, though — an entry written there gets an owner, and the Configurations API then neither lists it nor serves it as published.
Using the SDK
The @mapcentia/gc2-sdk exposes the API through the Configurations class. The management methods need a token from the database owner; the getPublicConfiguration* methods never send one. Keys are URL-encoded for you, and errors are thrown as CentiaApiError with .status and .code:
import { createCentiaClient, Configurations } from '@mapcentia/gc2-sdk'
const configurations = new Configurations(createCentiaClient({ baseUrl, auth: { getAccessToken } }))
// Create (201) — all four fields are required; body is JSON text.
// The generated keys are read from the Location header.
const { keys } = await configurations.postConfiguration({
name: 'My map',
description: 'Configuration for the public map',
published: true,
body: JSON.stringify({ brandName: 'My map' }),
})
const key = keys[0] // 'configuration_my_map_673211a0b1c2d312345678'
// List all (published or not), read one, or read several
const all = await configurations.getConfiguration()
const one = await configurations.getConfiguration(key)
const some = await configurations.getConfiguration([key, otherKey])
// Partial update (303) — any subset of the four fields; the key never changes
await configurations.patchConfiguration(key, { published: false })
// Delete one or several (204) — if any key is unknown, nothing is deleted
await configurations.deleteConfiguration([key, otherKey])
// Without a token: published configurations only
const published = await configurations.getPublicConfiguration('mydb')
const config = await configurations.getPublicConfiguration('mydb', key)
// The body, parsed — and the .json URL to give Vidi (no request is made)
const vidiConfig = await configurations.getPublicConfigurationBody<{ brandName: string }>('mydb', key)
const url = configurations.publicConfigurationUrl('mydb', key)
Fields
| Field | Description |
|---|---|
key | Server-generated identifier, configuration_<name>_<id> — read-only. Fixed at creation; never sent in a body. |
name | Name of the configuration. Required when creating; must not be empty. |
description | Free-text description. Required when creating; may be an empty string. |
published | When true, the configuration can be read without a token. Required when creating. |
body | The Vidi configuration as JSON text. Must parse to a JSON object or array. Stored and returned unchanged. Required when creating. |
Errors
| Status | Meaning |
|---|---|
400 | INVALID_REQUEST — body is not JSON text for an object or array, a malformed key, a key on POST, no key or several keys on PATCH, no key on DELETE, or a request body that is not an object (or, for POST, a non-empty list of objects). |
400 | INPUT_VALIDATION_ERROR — a missing, unknown or null field, or a value of the wrong type. |
403 | SUPER_USER_ONLY — a sub-user called a management route. |
404 | CONFIGURATION_NOT_FOUND — the key does not exist; on the token-less route also when the configuration is not published. |
404 | DATABASE_NOT_FOUND — the database in the path of the token-less route does not exist. |