Skip to content

.NET for Easit GO WebAPI

Basics

To get a basic understanding of the WebAPI in Easit GO we recommend you to start with reading the following articles before jumping ahead.

In this article we will only use the REST endpoint (/integration-api) in Easit GO and therefor only use JSON examples.

You can find the specification of the models used for requests and responses here.

Variables

We start by setting some variables that can be used later in our program.

1
2
3
4
string baseUrl = "https://urlToEasitGO/integration-api";
string apiKey = "myApiKey";
string view = "viewToGetObjectsFrom";
string importHandler = "importhandlerToImportObjectWith";

Client

We then create a new HTTP client that we will send the request with.

1
2
3
4
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.ConnectionClose = true;

Request

We create a new HTTP request message.

1
HttpRequestMessage requestMessage = new HttpRequestMessage();

Authorization

When we call Easit GO WebAPI, we need to authentication our self and therefor add a authentication header to the request.

1
2
3
String authenticationString = $"{apiKey}:";
String base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(AuthenticationString));
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", EncodedAuthenticationString);

HTTP Methods

Depending on what type of request (GET objects from Easit GO or POST object to Easit GO) we would like to send, we set the appropriate method.

1
2
3
requestMessage.Method = HttpMethod.Get;
// OR
requestMessage.Method = HttpMethod.Post;

Basic GET request

In our GET example we would like to get the first page from the view and that would look something like this. new GetItemsRequest() will generate a correctly formatted object that we then use to create JSON content with, and set that JSON content as the content of the request.

1
GetItemsRequest requestBody = new GetItemsRequest(null, null, null, view);

Basic POST request

In our POST example we would like to post a simple object with 2 properties to Easit GO, more specifically the importhandler importhandlerToImportObjectWith, with the id 1. The id can be anything you want, it is only and id for the object in the request body.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
List<Property> properties = new List<Property>
{
    new Property("value1", "propName1"),
    new Property("value2", "propName2")
};
ItemToImport importItem = new ItemToImport(null, "1", properties);
List<ItemToImport> itemsToImport = new List<ItemToImport>
{
    importItem
};
ImportItemsRequest requestBody = new ImportItemsRequest(importHandler, itemsToImport);

Set the content of the request

Once we have a request body we set it as the request message content as JSON content.

1
requestMessage.Content = JsonContent.Create(requestBody);

Send request and read response

We then send the request to Easit GO and read the response if the status code indicated success.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
try
{
    HttpResponseMessage response = client.Send(requestMessage);
    if (response.IsSuccessStatusCode)
    {
        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
    }
} catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}