State Resource
Manages learner state for an activity.

createState

Creates or merges into a state document by the agent, activity identifier and state identifier.

Example

1
const agent: Agent = {
2
objectType: "Agent",
3
name: "Test Agent",
4
mbox: "mailto:[email protected]"
5
};
6
const activityId: string = "https://example.com/activities/test-activity";
7
const stateId: string = activityId + "/states/myStateId";
8
const state: DocumentJson = {
9
myKey: "myValue"
10
};
11
12
xapi.createState({
13
agent: agent,
14
activityId: activityId,
15
stateId: stateId,
16
state: state
17
});
Copied!

Parameters

Parameter
Type
Required
Description
agent
Agent
true
The agent experiencing the AU.
activityId
string
true
The URI of the activity.
stateId
string
true
The URI of the state to be created or merged into.
state
true
The state data to be stored.
registration
string
false
The registration associated with this state.
etag
string
false
The ETag of the original document if merging.
matchHeader
string
false
The ETag header type. Accepts "If-Match" or "If-None-Match".

Returns

This method returns an AxiosPromise with empty success data if successful.

setState

Creates or overwrites a state document by the agent, activity identifier and state identifier.

Example

1
const agent: Agent = {
2
objectType: "Agent",
3
name: "Test Agent",
4
mbox: "mailto:[email protected]"
5
};
6
const activityId: string = "https://example.com/activities/test-activity";
7
const stateId: string = activityId + "/states/myStateId";
8
const state: Document = {
9
myKey: "myValue"
10
};
11
12
xapi.setState(agent, activityId, stateId, state);
Copied!

Parameters

Parameter
Type
Required
Description
agent
Agent
true
The agent experiencing the AU.
activityId
string
true
The URI of the activity.
stateId
string
true
The URI of the state to be created or overwritten.
state
Document
true
The state data to be stored.
registration
string
false
The registration associated with this state.
etag
string
false
The ETag of the original document if overwriting.
matchHeader
string
false
The ETag header type. Accepts "If-Match" or "If-None-Match".
contentType
string
false
The content type of the state data.

Returns

This method returns an AxiosPromise with empty success data if successful.

getStates

Gets an array of state identifiers by the agent and activity identifier.

Example

1
const agent: Agent = {
2
objectType: "Agent",
3
name: "Test Agent",
4
mbox: "mailto:[email protected]"
5
};
6
const activityId: string = "https://example.com/activities/test-activity";
7
8
xapi.getStates({
9
agent: agent,
10
activityId: activityId
11
}).then((result: AxiosResponse<string[]>) => {
12
const states: string[] = result.data;
13
console.log(states); // ["https://example.com/activities/test-activity/states/myStateId"]
14
});
Copied!

Parameters

Parameter
Type
Required
Description
agent
Agent
true
The agent experiencing the AU.
activityId
string
true
The URI of the activity.
registration
string
false
The registration associated with this state.
since
Timestamp
false
Only return States stored since specified Timestamp.
useCacheBuster
boolean
false
Enables cache busting.

Returns

This method returns an AxiosPromise with the success data containing an array of state identifiers if successful.

getState

Gets a state document by the agent, activity identifier and the state identifier.

Example

1
const agent: Agent = {
2
objectType: "Agent",
3
name: "Test Agent",
4
mbox: "mailto:[email protected]"
5
};
6
const activityId: string = "https://example.com/activities/test-activity";
7
const stateId: string = activityId + "/states/myStateId";
8
9
xapi.getState({
10
agent: agent,
11
activityId: activityId,
12
stateId: stateId
13
}).then((result: AxiosResponse<Document>) => {
14
const state = result.data;
15
// do stuff with state
16
});
Copied!

Parameters

Parameter
Type
Required
Description
agent
Agent
true
The agent experiencing the AU.
activityId
string
true
The URI of the activity.
stateId
string
true
The URI of the state to be retrieved.
registration
string
false
The registration associated with this state.
useCacheBuster
boolean
false
Enables cache busting.

Returns

This method returns an AxiosPromise with the success data containing the stored Document if successful.

deleteState

Deletes a state document by the agent, activity identifier and the state identifier.

Example

1
const agent: Agent = {
2
objectType: "Agent",
3
name: "Test Agent",
4
mbox: "mailto:[email protected]"
5
};
6
const activityId: string = "https://example.com/activities/test-activity";
7
const stateId: string = activityId + "/states/myStateId";
8
9
xapi.deleteState({
10
agent: agent,
11
activityId: activityId,
12
stateId: stateId
13
});
Copied!

Parameters

Parameter
Type
Required
Description
agent
Agent
true
The agent experiencing the AU.
activityId
string
true
The URI of the activity.
stateId
string
true
The URI of the state to be deleted.
registration
string
false
The registration associated with this stage.
etag
string
false
The ETag of the original document.

Returns

This method returns an AxiosPromise with empty success data if successful.

deleteStates

Deletes all state documents by the agent and activity identifier.

Example

1
const agent: Agent = {
2
objectType: "Agent",
3
name: "Test Agent",
4
mbox: "mailto:[email protected]"
5
};
6
const activityId: string = "https://example.com/activities/test-activity";
7
8
xapi.deleteStates({
9
agent: agent,
10
activityId: activityId
11
});
Copied!

Parameters

Parameter
Type
Required
Description
agent
Agent
true
The agent experiencing the AU.
activityId
string
true
The URI of the activity.
registration
string
false
The registration associated with this stage.
etag
string
false
The ETag of the original document if overwriting.

Returns

This method returns an AxiosPromise with empty success data if successful.
Last modified 1mo ago