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 4 : How to send a file using Add or POST.

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 byte[] GetDbFileById(Guid id)
{
    var client = new RestClient("http://localhost/");
    client.Authenticator = new OdysseeAuthenticator("APIUser", "123456@TESTAPI");
    var request = new RestRequest("/dbfile/GetFileContent/{id}",   Method.GET);
    request.AddUrlSegment("id", id.ToString()); // replaces matching token in request.Resource
    byte[]  data = client.DownloadData(request);
    return data;
}

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

    System.IO.File.WriteAllBytes("d:\\myfile.pdf", data);

Example 4

Here is the .net code to add file using post method. The DbTableId value is the one used for a company

private void PostDbFile
{
    var requestUrl = "DbFile";
    var filePath = "d:\\myfile.pdf";
    byte[] bytes = System.IO.File.ReadAllBytes(filePath);

    db_file file = new db_file
    {
        id = Guid.NewGuid(),
        db_table_id = Guid.Parse("A2D20910-D418-4630-ADDC-3507F408F154"),
        file_name = "myfile.pdf",
        db_table_name = "company",
        id_in_table = Guid.Parse("6842C6A4-1593-4E72-8658-02C0E99D873B"),
        file_content = bytes,
        name = "name of the file",
        description = "sample description",
        mime_type = "application/pdf"
    };

    var client = new RestClient("http://localhost/");
    client.Authenticator = new OdysseeAuthenticator("APIUser", "123456@TESTAPI");
    var request = new RestRequest(requestUrl, Method.POST);
    request.AddJsonBody(file);   
    var response = client.Execute(request);   
}

Here is the .net code to add file using add method.Also to add a file linked to a company.

private void AddDbFile
{
    var requestUrl = "DbFile/Add?db_table_id=A2D20910-D418-4630-ADDC-3507F408F154&id_in_table=6842C6A4-1593-4E72-8658-02C0E99D873B&description=description_here";
    var filePath = "d:\\myfile.pdf";
    byte[] bytes = System.IO.File.ReadAllBytes(filePath);

    var client = new RestClient("http://localhost/");
    client.Authenticator = new OdysseeAuthenticator("APIUser", "123456@TESTAPI");
    var request = new RestRequest(requestUrl, Method.POST);
    request.AddFile("Add", bytes, "file_name");
    var response = client.Execute(request);   
}