Skip to main content

Canvas

GET /canvas/:documentType

Get canvas embedded documents

Required scope: canvas:read

Parameters

NameTypeRequiredSourceDescription
documentTypestringparamsType of canvas document (tokens, tiles, drawings, lights, sounds, notes, templates, walls, regions)
clientIdstringqueryClient ID for the Foundry world
sceneIdstringqueryScene ID to query (defaults to the active scene)
documentIdstringquerySpecific document ID to retrieve
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

array - Array of embedded documents

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/canvas/tokens';
const params = {
clientId: 'fvtt_099ad17ea199e7e3'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': 'your-api-key-here'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "get-canvas-documents-result",
"requestId": "get-canvas-documents_1778896423147",
"sceneId": "tgYnjCnq6EFiREjl",
"documentType": "tokens",
"data": [
0: {
"actorId": "S6Nh5SfYPcyyUhRg",
"x": 400,
"y": 400,
"shape": 4,
"_id": "g0RJToymge8Rs7G2",
"name": "",
"displayName": 0,
"actorLink": false,
"delta": { 5 keys },
"width": 1,
"height": 1,
"texture": { 11 keys },
"elevation": 0,
"sort": 0,
"locked": false,
"lockRotation": false,
"rotation": 0,
"alpha": 1,
"hidden": false,
"disposition": -1,
"displayBars": 0,
"bar1": { 1 key },
"bar2": { 1 key },
"light": { 15 keys },
"sight": { 9 keys },
"detectionModes": [],
"occludable": { 1 key },
"ring": { 4 keys },
"turnMarker": { 4 keys },
"movementAction": null,
"_movementHistory": [],
"_regions": [],
"flags": {}
}
]
}

GET /measure-distance

Measure the distance between two points or tokens

Calculates the distance between two positions on the canvas, respecting the grid type and measurement rules. Points can be specified as coordinates or by referencing tokens by UUID or name.

Required scope: canvas:read

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
originXnumberbody, queryOrigin x coordinate (optional if originUuid/originName provided)
originYnumberbody, queryOrigin y coordinate
targetXnumberbody, queryTarget x coordinate (optional if targetUuid/targetName provided)
targetYnumberbody, queryTarget y coordinate
originUuidstringbody, queryUUID of the origin token
originNamestringbody, queryName of the origin token
targetUuidstringbody, queryUUID of the target token
targetNamestringbody, queryName of the target token
sceneIdstringbody, queryScene ID (defaults to active scene)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Distance measurement including units and grid spaces

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/measure-distance';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
originX: '0',
originY: '0',
targetX: '500',
targetY: '500'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': 'your-api-key-here'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "measure-distance-result",
"requestId": "measure-distance_1778896423503",
"data": {
"distance": 25,
"units": "ft",
"origin": {
"x": 0,
"y": 0
},
"target": {
"x": 500,
"y": 500
},
"sceneId": "tgYnjCnq6EFiREjl"
}
}

POST /canvas/:documentType

Create canvas embedded document(s)

Required scope: canvas:write

Parameters

NameTypeRequiredSourceDescription
documentTypestringparamsType of canvas document (tokens, tiles, drawings, lights, sounds, notes, templates, walls, regions)
dataobjectbodyDocument data object or array of objects to create
clientIdstringqueryClient ID for the Foundry world
sceneIdstringbody, queryScene ID to create in (defaults to the active scene)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Created document(s)

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/canvas/tokens';
const params = {
clientId: 'fvtt_099ad17ea199e7e3'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'POST',
headers: {
'x-api-key': 'your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"data": {
"x": 400,
"y": 400,
"actorId": "S6Nh5SfYPcyyUhRg"
}
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "create-canvas-document-result",
"requestId": "create-canvas-document_1778896423071",
"sceneId": "tgYnjCnq6EFiREjl",
"documentType": "tokens",
"data": [
0: {
"actorId": "S6Nh5SfYPcyyUhRg",
"x": 400,
"y": 400,
"shape": 4,
"_id": "g0RJToymge8Rs7G2",
"name": "",
"displayName": 0,
"actorLink": false,
"delta": { 5 keys },
"width": 1,
"height": 1,
"texture": { 11 keys },
"elevation": 0,
"sort": 0,
"locked": false,
"lockRotation": false,
"rotation": 0,
"alpha": 1,
"hidden": false,
"disposition": -1,
"displayBars": 0,
"bar1": { 1 key },
"bar2": { 1 key },
"light": { 15 keys },
"sight": { 9 keys },
"detectionModes": [],
"occludable": { 1 key },
"ring": { 4 keys },
"turnMarker": { 4 keys },
"movementAction": null,
"_movementHistory": [],
"_regions": [],
"flags": {}
}
]
}

PUT /canvas/:documentType

Update a canvas embedded document

Required scope: canvas:write

Parameters

NameTypeRequiredSourceDescription
documentTypestringparamsType of canvas document (tokens, tiles, drawings, lights, sounds, notes, templates, walls, regions)
documentIdstringbody, queryID of the document to update
dataobjectbodyObject containing the fields to update
clientIdstringqueryClient ID for the Foundry world
sceneIdstringbody, queryScene ID containing the document (defaults to the active scene)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Updated document

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/canvas/tokens';
const params = {
clientId: 'fvtt_099ad17ea199e7e3'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'PUT',
headers: {
'x-api-key': 'your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"documentId": "g0RJToymge8Rs7G2",
"data": {
"x": 450,
"y": 450
}
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "update-canvas-document-result",
"requestId": "update-canvas-document_1778896423151",
"sceneId": "tgYnjCnq6EFiREjl",
"documentType": "tokens",
"data": [
0: {
"actorId": "S6Nh5SfYPcyyUhRg",
"x": 450,
"y": 450,
"shape": 4,
"_id": "g0RJToymge8Rs7G2",
"name": "",
"displayName": 0,
"actorLink": false,
"delta": { 5 keys },
"width": 1,
"height": 1,
"texture": { 11 keys },
"elevation": 0,
"sort": 0,
"locked": false,
"lockRotation": false,
"rotation": 0,
"alpha": 1,
"hidden": false,
"disposition": -1,
"displayBars": 0,
"bar1": { 1 key },
"bar2": { 1 key },
"light": { 15 keys },
"sight": { 9 keys },
"detectionModes": [],
"occludable": { 1 key },
"ring": { 4 keys },
"turnMarker": { 4 keys },
"movementAction": null,
"_movementHistory": [],
"_regions": [],
"flags": {}
}
]
}

DELETE /canvas/:documentType

Delete a canvas embedded document

Required scope: canvas:write

Parameters

NameTypeRequiredSourceDescription
documentTypestringparamsType of canvas document (tokens, tiles, drawings, lights, sounds, notes, templates, walls, regions)
documentIdstringqueryID of the document to delete
clientIdstringqueryClient ID for the Foundry world
sceneIdstringqueryScene ID containing the document (defaults to the active scene)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Deletion result

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/canvas/tokens';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
documentId: 'g0RJToymge8Rs7G2'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'DELETE',
headers: {
'x-api-key': 'your-api-key-here'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "delete-canvas-document-result",
"requestId": "delete-canvas-document_1778896423184",
"sceneId": "tgYnjCnq6EFiREjl",
"documentType": "tokens",
"success": true
}

POST /move-token

Move a token to specific coordinates

Moves a token on the canvas to the specified x,y position, optionally animating through waypoints. Token can be identified by UUID or name.

Required scope: canvas:write

Parameters

NameTypeRequiredSourceDescription
xnumberbody, queryTarget x coordinate
ynumberbody, queryTarget y coordinate
clientIdstringqueryClient ID for the Foundry world
uuidstringbody, queryUUID of the token to move (optional if name provided)
namestringbody, queryName of the token to move (optional if uuid provided)
waypointsarraybody, queryArray of waypoint objects with x and y coordinates to animate through before reaching final position
animatebooleanbody, queryWhether to animate the movement (default: true)
sceneIdstringbody, queryScene ID (defaults to active scene)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Result of the token movement including new position

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/move-token';
const params = {
clientId: 'fvtt_099ad17ea199e7e3'
};
const queryString = new URLSearchParams(params).toString();
const url = `${baseUrl}${path}?${queryString}`;

const response = await fetch(url, {
method: 'POST',
headers: {
'x-api-key': 'your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"uuid": "Actor.S6Nh5SfYPcyyUhRg",
"x": 200,
"y": 200,
"animate": false
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "move-token-result",
"requestId": "move-token_1778896423481",
"data": {
"tokenUuid": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG",
"name": "Updated Test Actor",
"x": 200,
"y": 200,
"sceneId": "tgYnjCnq6EFiREjl"
}
}