GetScenarios API

GetScenarios API Features

Examples in this guide reference code from the APS Web Service Client Sample project with a web service proxy configured. If you are just getting started with the APS Web Services APIs, please see our client sample.

API Function

The GetScenarios API is used to retrieve a list of existing scenarios in PlanetTogether matching the specified ScenarioType—Whatif, Live, Published, RuleSeek, InsertJobs, Game, ShortTerm, Pruned—or all types by default.

API Parameters

  • Username (string) - the user's username performing the call
  • Password (string) - the user's related password
  • TimeoutDuration (TimeSpan) - the time to wait when trying to connect to Extra Services or getting a data lock. If this parameter is not included in the request, a default value of 30 seconds will be used.
  • ScenarioType (string) - the scenario type (i.e. Whatif, Live, Published, RuleSeek, InsertJobs, Game, ShortTerm, Pruned)
  • TimeoutMinutes (int) - the number of minutes the call should wait to receive a response

API Call

Once the typed Request is created, the API call can be made using the following format:

 GetScenariosResponse resp = client.GetScenarios(getScenariosRequest);

API Request

This API request inherits from ApsWebServiceRequest. Check out our KB article on the API Request Base classes to learn more: Basic API Structure

To use the API, you must create a typed Request using the Request Data Contract. The related web client will use this Request to trigger the process.

  • Data Contract
[DataContract]
public class GetScenariosRequest : ApsWebServiceRequestBase
{
[DataMember(IsRequired = false)]
public string ScenarioType { get; set; }

[DataMember(IsRequired = false)]
public double TimeoutMinutes { get; set; } = 5;
}

      API Request Example

      //Create a typed request
      APSWebServiceRef.GetScenariosRequest getScenariosRequest = new GetScenariosRequest()
      {
      ScenarioType = a_scenarioType,
      TimeoutMinutes = a_timeout
      };

      //Request Base
      getScenariosRequest.UserName = a_username;
      getScenariosRequest.Password = a_pwd;

      API Response

       

      All API calls return a Response object to help determine the result of the call. Check out our Basic API Structure KB article for more information.

      API Response Example

      //Sending a request
      a_start = DateTime.Now;
      GetScenariosResponse resp = client.GetScenarios(getScenariosRequest);
      Console.WriteLine($"Response received after '{DateTime.Now.Subtract(start)}'");

      API Scenario Confirmation

      The API Scenario Confirmation holds the specific values related to a PlanetTogether scenario. The related API Response contains a reference to each scenario's property values using this Data Contract.

      • Data Contract - Reference the API Response section of the CopyScenario API article for a related data contract.
      • Response Example
      //Sending a request
      a_start = DateTime.Now;
      GetScenariosResponse resp = client.GetScenarios(getScenariosRequest);
      Console.WriteLine($"Response received after '{DateTime.Now.Subtract(start)}'");

      //Display response scenario confirmation data
      if (resp.Confirmations.Length > 0)
      {
      Console.WriteLine($"{Environment.NewLine}{resp.Confirmations.Length} Current scenarios of Type '{(string.IsNullOrEmpty(scenarioType) ? "All Types" : scenarioType)}'{Environment.NewLine}");
      foreach (ScenarioConfirmation scenarioInfo in resp.Confirmations)
      {
      Console.WriteLine($" Name:{scenarioInfo.ScenarioName}{Environment.NewLine} Id:{scenarioInfo.ScenarioId}{Environment.NewLine} Type:{scenarioInfo.ScenarioType}{Environment.NewLine}");
      }
      }