Skip to main content

Encounter

GET /encounters

Get all active encounters

Retrieves a list of all currently active encounters in the Foundry world.

Required scope: encounter:read

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

array - An array of active encounters with details

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/encounters';
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": "encounters-result",
"requestId": "encounters_1778896436545",
"encounters": [
0: {
"id": "PB0vvGNb0h66rsIi",
"round": 1,
"turn": 0,
"current": true,
"combatants": [ 1 item ]
}
]
}

POST /start-encounter

Start a new encounter

Initiates a new encounter in the Foundry world.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
tokensarraybodyArray of token UUIDs to include in the encounter
startWithSelectedbooleanbodyWhether to start with selected tokens
startWithPlayersbooleanbodyWhether to start with players
rollNPCbooleanbodyWhether to roll for NPCs
rollAllbooleanbodyWhether to roll for all tokens
namestringbodyThe name of the encounter
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the started encounter

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/start-encounter';
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({
"startWithSelected": true,
"rollAll": true
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "start-encounter-result",
"requestId": "start-encounter_1778896436492",
"encounterId": "PB0vvGNb0h66rsIi",
"encounter": {
"id": "PB0vvGNb0h66rsIi",
"round": 1,
"turn": 0,
"combatants": [
0: { 8 keys }
]
}
}

POST /next-turn

Advance to the next turn in the encounter

Moves the encounter to the next turn.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the next turn

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/next-turn';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "next-turn-result",
"requestId": "next-turn_1778896436560",
"encounterId": "PB0vvGNb0h66rsIi",
"action": "nextTurn",
"currentTurn": 0,
"currentRound": 2,
"actorTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG.Actor.S6Nh5SfYPcyyUhRg",
"tokenTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG",
"encounter": {
"id": "PB0vvGNb0h66rsIi",
"round": 2,
"turn": 0
}
}

POST /next-round

Advance to the next round in the encounter

Moves the encounter to the next round.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the next round

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/next-round';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "next-round-result",
"requestId": "next-round_1778896436575",
"encounterId": "PB0vvGNb0h66rsIi",
"action": "nextRound",
"currentTurn": 0,
"currentRound": 3,
"actorTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG.Actor.S6Nh5SfYPcyyUhRg",
"tokenTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG",
"encounter": {
"id": "PB0vvGNb0h66rsIi",
"round": 3,
"turn": 0
}
}

POST /last-turn

Go back to the last turn in the encounter

Moves the encounter back to the last turn.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the last turn

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/last-turn';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "last-turn-result",
"requestId": "last-turn_1778896436584",
"encounterId": "PB0vvGNb0h66rsIi",
"action": "previousTurn",
"currentTurn": 0,
"currentRound": 2,
"actorTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG.Actor.S6Nh5SfYPcyyUhRg",
"tokenTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG",
"encounter": {
"id": "PB0vvGNb0h66rsIi",
"round": 2,
"turn": 0
}
}

POST /last-round

Go back to the last round in the encounter

Moves the encounter back to the last round.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the last round

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/last-round';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "last-round-result",
"requestId": "last-round_1778896436595",
"encounterId": "PB0vvGNb0h66rsIi",
"action": "previousRound",
"currentTurn": 0,
"currentRound": 1,
"actorTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG.Actor.S6Nh5SfYPcyyUhRg",
"tokenTurn": "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG",
"encounter": {
"id": "PB0vvGNb0h66rsIi",
"round": 1,
"turn": 0
}
}

POST /end-encounter

End an encounter

Ends the current encounter in the Foundry world.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the ended encounter

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/end-encounter';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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'
}
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "end-encounter-result",
"requestId": "end-encounter_1778896436617",
"encounterId": "PB0vvGNb0h66rsIi",
"message": "Encounter successfully ended"
}

POST /add-to-encounter

Add tokens to an encounter

Adds selected tokens or specified UUIDs to the current encounter.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
selectedbooleanquery, bodyWhether to get the selected entity
uuidsarraybodyThe UUIDs of the tokens to add
rollInitiativebooleanbodyWhether to roll initiative for the added tokens
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the updated encounter

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/add-to-encounter';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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({
"selected": true,
"uuids": [],
"rollInitiative": true
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "add-to-encounter-result",
"requestId": "add-to-encounter_1778896436611",
"encounterId": "PB0vvGNb0h66rsIi",
"added": [
0: "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG"
],
"failed": []
}

POST /remove-from-encounter

Remove tokens from an encounter

Removes selected tokens or specified UUIDs from the current encounter.

Required scope: encounter:manage

Parameters

NameTypeRequiredSourceDescription
clientIdstringqueryClient ID for the Foundry world
encounterstringbody, queryThe ID of the encounter (optional, defaults to current encounter)
selectedbooleanquery, bodyWhether to get the selected entity
uuidsarraybodyThe UUIDs of the tokens to remove
userIdstringquery, bodyFoundry user ID or username to scope permissions (omit for GM-level access)

Returns

object - Details of the updated encounter

Try It Out

Code Examples

const baseUrl = 'http://localhost:3010';
const path = '/remove-from-encounter';
const params = {
clientId: 'fvtt_099ad17ea199e7e3',
encounterId: 'PB0vvGNb0h66rsIi'
};
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({
"selected": true
})
});
const data = await response.json();
console.log(data);

Response

Status: 200

{
"type": "remove-from-encounter-result",
"requestId": "remove-from-encounter_1778896436602",
"encounterId": "PB0vvGNb0h66rsIi",
"removed": [
0: "Scene.tgYnjCnq6EFiREjl.Token.TOInpAfNZ6GRAJaG"
],
"failed": []
}