# Using the Web API

The web api service must be first installed and started (see topic [Web Api Service Setup](https://docs.appstrategy.com/apprules-r-documentation/platform/self-hosting/software-installation/webapi))

\
The following Postman screens shows how to setup a sample project call using the web API:

![](https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFjmFrZ8sef1J7qkr6H%2F-MHutjX5Gl1xx30fIFd1%2F-MHuuGPGRD2hWI0hJpgt%2Fimage.png?alt=media\&token=d34b4c71-3faa-419b-ba2e-ec64d07d7ace)

![](https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFjmFrZ8sef1J7qkr6H%2F-MHutjX5Gl1xx30fIFd1%2F-MHuuWxub_3PCfuELo71%2Fimage.png?alt=media\&token=a4e75054-5ae4-4890-b95b-a11912c22038)

![](https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFjmFrZ8sef1J7qkr6H%2F-MHutjX5Gl1xx30fIFd1%2F-MHuu_mHT2X_ebqXKB20%2Fimage.png?alt=media\&token=8c074394-3106-4934-9ef5-2d6297fb2e0f)

### Body structure

| **Connection Params** | Description                                                                                                                                                                                                          |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Organization          | The organization. When not specified, Default is used                                                                                                                                                                |
| DatabaseId            | The id the project database.                                                                                                                                                                                         |
| UserId                | The user id for running the job                                                                                                                                                                                      |
| Password              | The encrypted user password for running the job.                                                                                                                                                                     |
| ApiKey                | Security feature, Optional if a webapi key is not specified in the WebApi service config file, Must match the ApiKey on the server if specified - the project will be only run if Apikeys match on client and server |

| **Execution Params** | Description                                                                                                                                                                                                                                                           |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Projectid            | The integer id of the project to run                                                                                                                                                                                                                                  |
| Reference            | Optional reference for the job                                                                                                                                                                                                                                        |
| Interactive          | Mode for running the job: false = background (the project is launched only), true = foreground (the api waits for the project to end (used when return arguments are specified -example waiting for a return code to execute another project), Note: Default is false |
| Arguments            | Optional name/value dictionary of arguments for running the job in Json format, leave blank if none (remove the Arguments json)                                                                                                                                       |

The following C# shows how to setup a sample project using the web api:

```csharp
using System;
using System.Collections.Generic;
using System.Configuration;
using Newtonsoft.Json;
using appRulesPortal.WebApi.Client;
using appRulesPortal.WebApi.Params;
namespace SampleWebApi
{
 static class Program
 {
  /// <summary>
 /// The main entry point for the application.
 /// </summary>
 [STAThread]
 static int Main(string[] args)
 {
 if (args == null)
 return 4;
  var connectionParams = 
new
 ConnectionParams();
 var executionParams = 
new
 ExecutionParams();
  connectionParams.Organization = args[0]; //Organization (or use * for Default)
 connectionParams.DatabaseId = Convert.ToInt32(args[1]); //project database id
 connectionParams.UserId = args[2]; //user id
 connectionParams.Password = args[3]; //password
  executionParams.ProjectId = Convert.ToInt32(args[4]); //project id;
 if (args.Length > 5)
 {
 executionParams.Reference = args[5]; //reference for job (or use * Note: No spaces
 if (args.Length > 6)
 executionParams.Arguments = (Dictionary<string, object>)JsonConvert.DeserializeObject(args[5], 
typeof
(Dictionary<string, object>));
 }
  var apiKey = ConfigurationManager.AppSettings["ApiKey"];
 if(!String.IsNullOrEmpty(apiKey))
 connectionParams.ApiKey = apiKey;
  var serviceUrl = ConfigurationManager.AppSettings["WebApiUrl"];
 if (String.IsNullOrEmpty(serviceUrl))
 serviceUrl = "http://localhost:8082/";
  var client = 
new
 PortalClient(serviceUrl); //initialize the url of the WebApi service
 //var result = client.Execute(connectionParams, null).Result; //arguments can be null since it is defined in connectionParams.args
 client.Execute(connectionParams, executionParams);
 return 0;
 }
 }
 }
```
