Skip to main content

Retrieving state

This section provides information on how to retrieve previously created tasks.

API reference:

Required scopes:

  • Data/Buildby.Taskurai/state/read

Optional scopes:

  • Data/Buildby.Taskurai/sensitive/read: Can return sensitive data.

Prerequisites

Retrieving state entry by id

To retrieve a state entry by using the state id.

var cart = stateClient.GetState<dynamic>("DefaultStateStore", "webshop::session::b470bb74-193f-4637-83db-be0ef23f99fd::cart");

Console.WriteLine(JsonSerializer.Serialize(cart, serializerOptions));

Next, run the console application to validate:

dotnet run

Sample output:

{
"items": {
"Item A": 10,
"Item B": 5
}
}

Retrieving state entry by state reference

When a state entry is returned, it contains an easy to use state reference, can be passed to tasks, commands, steps to retrieve state entries.

// Get state client
var stateClient = taskurai.GetStateClient();

var stateReference = new StateReference("DefaultStateStore", "webshop::session::b470bb74-193f-4637-83db-be0ef23f99fd::cart");

var cart = stateClient.GetState<dynamic>(stateReference);

Console.WriteLine(JsonSerializer.Serialize(cart, serializerOptions));

Next, run the console application to validate:

dotnet run

Sample output:

{
"items": {
"Item A": 10,
"Item B": 5
}
}

Retrieving blob state entry

A blob state entry can be retrieved by multiple ways (stream, file), this sample saves the blob to a file.

// Get state client
var stateClient = taskurai.GetStateClient();

var stateResponse = stateClient.GetBlobStateTo(
"DefaultStateStore",
"ml::model::timeseries::forecasting::v1",
"model_timeseries.bin"); // Export file path

Console.WriteLine(JsonSerializer.Serialize(stateResponse, serializerOptions));

Next, run the console application to validate:

dotnet run

Sample output:

{
"id": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::ml::model::timeseries::forecasting::v1",
"partitionKey": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::ml::model::timeseries::forecasting::v1",
"created": "2026-03-27T17:23:25.4413203+00:00",
"createdBy": "d8e9cb3f-ffeb-4915-bb15-6681a3bcd175",
"modified": "2026-03-27T17:23:25.4413203+00:00",
"modifiedBy": "d8e9cb3f-ffeb-4915-bb15-6681a3bcd175",
"hasBlob": true,
"contentType": "application/octet-stream",
"tags": {
"trained_on": "sales_forecasting_dataset",
"accuracy": "0.95",
"description": "Time series forecasting model for sales predictions",
"model_type": "LSTM",
"framework": "Deep Learning"
},
"stateStoreName": "DefaultStateStore",
"isolationMode": true,
"isolationKey": "dd10b001-addd-45c2-94a6-932282b7515c",
"ttl": -1,
"etag": "\u0022ac00de08-0000-0d00-0000-69c6bd0d0000\u0022",
"eTagBlob": "\u00220x8DE8C258DCE6990\u0022",
"stateReference": {
"stateStoreName": "DefaultStateStore",
"id": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::ml::model::timeseries::forecasting::v1"
}
}

Retrieving blob contents

A blob state entry can be retrieved as a BinaryData payload.

// Get state client
var stateClient = taskurai.GetStateClient();

var readContents = stateClient.GetBlobStateContent("DefaultStateStore", "ml::config::commonconfig");

// Binary data contents
BinaryData contents = readContents.BlobDownloadResult.Content;

// Parse document
var document = JsonDocument.Parse(contents);

Retrieving bulk state

State can be retrieved in bulk, optimizing the number of roundtrips to the API.

// Get state client
var stateClient = taskurai.GetStateClient();

var stateIds = new List<string>
{
"webshop::session::893c1f6f-f10c-4131-bcfe-cb0385e322b4::customer",
"webshop::session::893c1f6f-f10c-4131-bcfe-cb0385e322b4::cart"
};

var stateBulkInput = new StateGetBulkInput(stateIds)
{
MaxParallelism = 10
};

var stateResponseList = stateClient.GetBulkState("DefaultStateStore", stateBulkInput);

Console.WriteLine(JsonSerializer.Serialize(stateResponseList, serializerOptions));

Next, run the console application to validate:

dotnet run

Sample output:

[
{
"id": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::webshop::session::85909b63-91a1-4186-ba4a-5013d49e3a00::customer",
"partitionKey": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::webshop::session::85909b63-91a1-4186-ba4a-5013d49e3a00::customer",
"created": "2026-03-27T17:29:28.9058571+00:00",
"createdBy": "d8e9cb3f-ffeb-4915-bb15-6681a3bcd175",
"modified": "2026-03-27T17:29:28.9058571+00:00",
"modifiedBy": "d8e9cb3f-ffeb-4915-bb15-6681a3bcd175",
"tags": {},
"stateStoreName": "DefaultStateStore",
"isolationMode": true,
"isolationKey": "dd10b001-addd-45c2-94a6-932282b7515c",
"ttl": 3600,
"etag": "\u0022ac00e922-0000-0d00-0000-69c6be780000\u0022",
"value": {
"name": "Jane Doe",
"email": "jane.doe@mail.net",
"address": {
"street": "",
"zipcode": "",
"city": "",
"state": "",
"country": "US"
}
},
"stateReference": {
"stateStoreName": "DefaultStateStore",
"id": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::webshop::session::85909b63-91a1-4186-ba4a-5013d49e3a00::customer"
}
},
{
"id": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::webshop::session::85909b63-91a1-4186-ba4a-5013d49e3a00::cart",
"partitionKey": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::webshop::session::85909b63-91a1-4186-ba4a-5013d49e3a00::cart",
"created": "2026-03-27T17:29:28.9058571+00:00",
"createdBy": "d8e9cb3f-ffeb-4915-bb15-6681a3bcd175",
"modified": "2026-03-27T17:29:28.9058571+00:00",
"modifiedBy": "d8e9cb3f-ffeb-4915-bb15-6681a3bcd175",
"tags": {},
"stateStoreName": "DefaultStateStore",
"isolationMode": true,
"isolationKey": "dd10b001-addd-45c2-94a6-932282b7515c",
"ttl": 3600,
"etag": "\u0022ac00ea22-0000-0d00-0000-69c6be780000\u0022",
"value": {
"items": {
"Item A": 10,
"Item B": 5
}
},
"stateReference": {
"stateStoreName": "DefaultStateStore",
"id": "isolation::dd10b001-addd-45c2-94a6-932282b7515c::state::webshop::session::85909b63-91a1-4186-ba4a-5013d49e3a00::cart"
}
}
]