> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.truvo.com/llms.txt.

# Select a sandbox scenario

POST https://api.truvo.com/v1/sandbox/scenarios
Content-Type: application/json

Reference: https://docs.truvo.com/api-reference/set-sandbox-scenario

## Authentication

- `Authorization` header (bearer token, required) — Your Truvo API key, sent as a bearer token. The prefix selects sandbox (trv_sandbox_) or live (trv_live_).

## Request

### Headers

- `Idempotency-Key` (string, required) — A caller-chosen request key. A key replays for at least 24 hours. The same key with the same body replays the first answer; the same key with a different body is a conflict.

### Body (application/json)

This endpoint expects a SandboxScenarioCommand.

- `scenario` (string, required)

## Response

### 200

Select a sandbox scenario. Sandbox keys only.

- `control` (enum, required)
  - Allowed values: `select_scenario`, `advance_time`, `force_expiry`, `replay_events`, `reset`
- `workspace` (SandboxWorkspaceView, required)
- `replay` (SandboxControlResultReplay, required, nullable)
- `removed` (map from string to integer, required, nullable)

## Errors

### 400 Bad Request Error

Error envelope. One of: invalid_json.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 401 Unauthorized Error

Error envelope. One of: authentication_failed.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 403 Forbidden Error

Error envelope. One of: forbidden.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 404 Not Found Error

Error envelope. One of: not_found.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 409 Conflict Error

Error envelope. One of: conflict.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 413 Content Too Large Error

Error envelope. One of: request_too_large.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 422 Unprocessable Entity Error

Error envelope. One of: invalid_input.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 429 Too Many Requests Error

Error envelope. One of: rate_limited.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 500 Internal Server Error

Error envelope. One of: internal_error.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 503 Service Unavailable Error

Error envelope. One of: service_unavailable.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

## Types

### SandboxWorkspaceView

- `partner_id` (string, required)
- `environment` ("sandbox", required)
- `active_scenario` (string, required, nullable)
- `clock_offset_seconds` (integer, required)
- `workspace_time` (datetime, required)
- `quotes_expired_at` (datetime, required, nullable)
- `reset_count` (integer, required)
- `scenario_catalog_version` (string, required)

### SandboxControlResultReplay

- `id` (string, required)
- `scenarioCode` (string, required)
- `notice` (string, required)
- `recovery` (string, required, nullable)
- `deliveries` (integer, required)

### ErrorEnvelopeError

- `code` (enum, required)
  - Allowed values: `authentication_failed`, `forbidden`, `not_found`, `invalid_input`, `invalid_json`, `invalid_cursor`, `needs_information`, `conflict`, `quote_expired`, `price_changed`, `purchase_not_supported`, `rate_limited`, `request_too_large`, `internal_error`, `service_unavailable`, `event_cursor_expired`
- `message` (string, required)
- `field_errors` (list of FieldError, required, nullable)
- `retry_action` (RetryAction, required)
- `doc_url` (string, required)

### FieldError

- `path` (string, required)
- `message` (string, required)

### RetryAction

- `type` (enum, required)
  - Allowed values: `none`, `retry`, `correct_input`, `supply_facts`, `read_status`, `use_new_request_key`, `wait`, `contact_support`
- `summary` (string, required)

## Examples

**Request**

```json
{
  "scenario": "string"
}
```

**Response**

```json
{
  "control": "select_scenario",
  "workspace": {
    "partner_id": "string",
    "environment": "string",
    "active_scenario": "string",
    "clock_offset_seconds": 1,
    "workspace_time": "2024-01-15T09:30:00Z",
    "quotes_expired_at": "2024-01-15T09:30:00Z",
    "reset_count": 1,
    "scenario_catalog_version": "string"
  },
  "replay": {
    "id": "string",
    "scenarioCode": "string",
    "notice": "string",
    "recovery": "string",
    "deliveries": 1
  },
  "removed": {}
}
```

**SDK Code**

```python
import requests

url = "https://api.truvo.com/v1/sandbox/scenarios"

payload = { "scenario": "string" }
headers = {
    "Idempotency-Key": "Idempotency-Key",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.truvo.com/v1/sandbox/scenarios';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': 'Idempotency-Key',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"scenario":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.truvo.com/v1/sandbox/scenarios"

	payload := strings.NewReader("{\n  \"scenario\": \"string\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "Idempotency-Key")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.truvo.com/v1/sandbox/scenarios")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = 'Idempotency-Key'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"scenario\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.truvo.com/v1/sandbox/scenarios")
  .header("Idempotency-Key", "Idempotency-Key")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"scenario\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.truvo.com/v1/sandbox/scenarios', [
  'body' => '{
  "scenario": "string"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => 'Idempotency-Key',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.truvo.com/v1/sandbox/scenarios");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "Idempotency-Key");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"scenario\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Idempotency-Key": "Idempotency-Key",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["scenario": "string"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.truvo.com/v1/sandbox/scenarios")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```