Odyssee Mobile

API User Guide

Here are some .net code examples used to communicate with our API.

  •  Example 1 : Getting an existing user unavailability.
  •  Example 2 : Creating a user_unavailability.
  •  Example 3 : Getting the file content byte [] from db_file table.

Example 1

In this example, we will get an existing unavailability

private string GetUserUnavailabilityById(Guid id)
{
    var client = new RestClient("https://developers.odysseemobile.com/api/");
    client.Authenticator = new HttpBasicAuthenticator("APIUser", "123456@TESTAPI");
    var request = new RestRequest("userunavailability/{id}", Method.GET);
    request.AddUrlSegment("id", id.ToString()); // replaces matching token in request.Resource
    var response = client.Execute(request);
    return response.Content;
}

What does it do ?

  • First, it creates a Rest Client and gives the url.
  • Then, it sets the basic authentification for this rest client.
  • Then it requests the specific url (for this method) with a GET method
  • Then it replaces the url segment “id” with the value received (the unavailability that we want)
  • Finally, it executes the request and receives a response

This is the result, directly in the browser


Example 2

Here we create an unavailability, using .net code that communicates with the API

private string AddUserUnavailability(String unavailabilitySerialized)
{
    var client = new RestClient("https://developers.odysseemobile.com/api/");
    client.Authenticator = new HttpBasicAuthenticator("APIUser", "123456@TESTAPI");
    var request = new RestRequest("userunavailability", Method.POST);
    request.AddParameter("text/xml", unavailabilitySerialized,ParameterType.RequestBody);
    var response = client.Execute(request);
    return response.Content; 
}

The object unavailabilitySerialized is the data of the unavailability.

Example of a serialized user_unavailability

<user_unavailability xmlns="http://schemas.datacontract.org/2004/07/Odyssee.Info.DTO" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <date_end>2013-02-17T00:00:00+01:00</date_end>
    <date_start>2013-02-15T00:00:00+01:00</date_start>
    <description>Pens &amp; Bags annuleerde afspraak te Oudenaarde en sneeuw. Rapporten, expense reports, telefoons, mails, voorbereiding Luxemburg, ...</description>
    <id>12345678-1234-1234-1234-123456789012</id>
    <user_id>81e29c98-37bc-49d2-88d8-46b473107d54</user_id>
    <user_unavailability_type_id>8c2258f0-e146-4c19-8493-7993b7655dda</user_unavailability_type_id>
</user_unavailability>


Example 3

Here is the .net code to get the file content byte [] from db_file table. This will return the file content of the db_file matches the given id.

private string GetDbFileById(Guid id)
{
    var client = new RestClient("http://localhost/");
    client.Authenticator = new OdysseeAuthenticator("APIUser", "123456@TESTAPI");
    var request = new RestRequest("/dbfile/getdbfilecontent/{id}",   Method.GET);
    request.AddUrlSegment("id", id.ToString()); // replaces matching token in request.Resource
    var response = client.Execute(request);
    return response.Content;
}

Use the following code to save it as a pdf file.

string res = response.Content.Replace("\"", "");
byte[] data = Convert.FromBase64String(res);
System.IO.File.WriteAllBytes("d:\\myfile.pdf", data);