> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# StartScenarios

POST https://api.voximplant.com/platform_api/StartScenarios

Runs JavaScript scenarios on a Voximplant server. The scenarios run in a new media session. To start a scenario, pass the routing rule ID associated with the necessary scenario. You can use both GET and POST requests at your choice. If you need to send custom data, we recommend to use the POST method and to include the data in the `custom_data` field of the request body. The maximum number of concurrent HTTP-requests is limited to 200. If this number is exceeded, this method returns the 429 code error (Too Many Requests) until the number of active requests is reduced. If you exceed this number, you get the 429 error code.

Allowed roles: `Owner`, `Admin`, `Developer`, `CallsSMS`.

**Example request:** Start the scripts from the account.

Reference: https://docs.voximplant.ai/api-reference/management-api/reference/scenarios/start-scenarios

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: management-api
  version: 1.0.0
paths:
  /StartScenarios:
    post:
      operationId: start-scenarios
      summary: StartScenarios
      description: >-
        Runs JavaScript scenarios on a Voximplant server. The scenarios run in a
        new media session. To start a scenario, pass the routing rule ID
        associated with the necessary scenario. You can use both GET and POST
        requests at your choice. If you need to send custom data, we recommend
        to use the POST method and to include the data in the `custom_data`
        field of the request body. The maximum number of concurrent
        HTTP-requests is limited to 200. If this number is exceeded, this method
        returns the 429 code error (Too Many Requests) until the number of
        active requests is reduced. If you exceed this number, you get the 429
        error code.


        Allowed roles: `Owner`, `Admin`, `Developer`, `CallsSMS`.


        **Example request:** Start the scripts from the account.
      tags:
        - subpackage_scenarios
      parameters:
        - name: user_id
          in: query
          description: The user ID. Run the scripts from the user if set
          required: false
          schema:
            type: integer
        - name: user_name
          in: query
          description: >-
            The user name that can be used instead of **user_id**. Run the
            scripts from the user if set
          required: false
          schema:
            type: string
        - name: application_id
          in: query
          description: The application ID
          required: false
          schema:
            type: integer
        - name: application_name
          in: query
          description: The application name that can be used instead of **application_id**
          required: false
          schema:
            type: string
        - name: rule_id
          in: query
          description: >-
            The rule ID that needs to be launched. Please note, the necessary
            scenario needs to be attached to the rule
          required: true
          schema:
            type: integer
        - name: script_custom_data
          in: query
          description: >-
            The script custom data, that can be accessed in the scenario via the
            <a
            href='/docs/references/voxengine/voxengine/customdata'>VoxEngine.customData()</a>
            method. Use the application/x-www-form-urlencoded content type with
            UTF-8 encoding
          required: false
          schema:
            type: string
        - name: reference_ip
          in: query
          description: >-
            Specifies the IP from the geolocation of predicted subscribers. It
            allows selecting the nearest server for serving subscribers
          required: false
          schema:
            type: string
        - name: server_location
          in: query
          description: >-
            Specifies the location of the server where the scenario needs to be
            executed. Has higher priority than `reference_ip`. Request
            [getServerLocations](https://api.voximplant.com/getServerLocations)
            for possible values
          required: false
          schema:
            type: string
        - name: Authorization
          in: header
          description: >-
            Voximplant Management API uses signed JWT tokens generated from your
            service-account private key. Pass the token in the `Authorization`
            header as a Bearer value:


            ```

            Authorization: Bearer $VOXIMPLANT_TOKEN

            ```


            See [Authorization](/api-reference/management-api/authorization) for
            ready-to-copy snippets in bash, Python, Node.js and Go that turn
            your `credentials.json` into a token.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/scenarios_StartScenarios_Response_200'
servers:
  - url: https://api.voximplant.com/platform_api
components:
  schemas:
    scenarios_StartScenarios_Response_200:
      type: object
      properties:
        result:
          type: integer
          description: Returns 1 if the request has been completed successfully
        media_session_access_url:
          type: string
          description: >-
            The URL to control a created media session. You can use it for
            arbitrary tasks such as stopping scenario or passing additional data
            to it. Making HTTP request on this URL results in the
            [AppEvents.HttpRequest](/docs/references/voxengine/appevents#httprequest)
            VoxEngine event being triggered for scenario, with HTTP request data
            passed to it
        media_session_access_secure_url:
          type: string
          description: >-
            The URL to control a created media session. You can use it for
            arbitrary tasks such as stopping scenario or passing additional data
            to it. Making HTTPS request on this URL results in the
            [AppEvents.HttpRequest](/docs/references/voxengine/appevents#httprequest)
            VoxEngine event being triggered for scenario, with HTTP request data
            passed to it
        call_session_history_id:
          type: integer
          description: >-
            The call session history ID. To search a call session result, paste
            the ID to the <a
            href='/api-reference/management-api/history/getcallhistory'>GetCallHistory</a>
            method's **call_session_history_id** parameter
      title: scenarios_StartScenarios_Response_200
  securitySchemes:
    JwtAuth:
      type: http
      scheme: bearer
      description: >-
        Voximplant Management API uses signed JWT tokens generated from your
        service-account private key. Pass the token in the `Authorization`
        header as a Bearer value:


        ```

        Authorization: Bearer $VOXIMPLANT_TOKEN

        ```


        See [Authorization](/api-reference/management-api/authorization) for
        ready-to-copy snippets in bash, Python, Node.js and Go that turn your
        `credentials.json` into a token.

```

## SDK Code Examples

```python Success
import requests

url = "https://api.voximplant.com/platform_api/StartScenarios"

querystring = {"rule_id":"1"}

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers, params=querystring)

print(response.json())
```

```javascript Success
const url = 'https://api.voximplant.com/platform_api/StartScenarios?rule_id=1';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

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

```go Success
package main

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

func main() {

	url := "https://api.voximplant.com/platform_api/StartScenarios?rule_id=1"

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

	req.Header.Add("Authorization", "Bearer <token>")

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

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

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

}
```

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

url = URI("https://api.voximplant.com/platform_api/StartScenarios?rule_id=1")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

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

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

HttpResponse<String> response = Unirest.post("https://api.voximplant.com/platform_api/StartScenarios?rule_id=1")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.voximplant.com/platform_api/StartScenarios?rule_id=1', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp Success
using RestSharp;

var client = new RestClient("https://api.voximplant.com/platform_api/StartScenarios?rule_id=1");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift Success
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.voximplant.com/platform_api/StartScenarios?rule_id=1")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```