Here are some .net code examples used to communicate with our API.
byte []
from db_file table.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 ?
This is the result, directly in the browser
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
2013-02-17T00:00:00+01:00 2013-02-15T00:00:00+01:00 Pens & Bags annuleerde afspraak te Oudenaarde en sneeuw. Rapporten, expense reports, telefoons, mails, voorbereiding Luxemburg, ... 12345678-1234-1234-1234-123456789012 81e29c98-37bc-49d2-88d8-46b473107d54 8c2258f0-e146-4c19-8493-7993b7655dda
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);
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);
}