Ga naar hoofdinhoud

Innobrix API

Innobrix biedt een eigen API aan om mee te integreren. Hieronder tref je voorbeeldcode aan (C#) en beneden op de pagina een lijst via Swagger met de mogelijke API endpoints.

Voorbeeldcode

Application.cs

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;

class Program
{
static async Task Main(string[] args)
{
// Base URL of the API
string baseUrl = "https://api.innobrix.net/api/v1.1/";
// Endpoint for retrieving projects
string projectEndpoint = "/public/projects";
// Bearer token for authorization (replace with your API-key found at https://studio.innobrix.net/integrations/)
string bearerToken = "API Key";

using (HttpClient client = new HttpClient())
{
// Set base address
client.BaseAddress = new Uri(baseUrl);

// Add the Authorization header
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);

try
{
// Make GET request to the endpoint
HttpResponseMessage response = await client.GetAsync(projectEndpoint);

// Ensure the response is successful
response.EnsureSuccessStatusCode();

// Read and display response content
string projectsData = await response.Content.ReadAsStringAsync();
Console.WriteLine($"projects: {projectsData}");

var projects = JsonConvert.DeserializeObject<Project[]>(projectsData);
if (projects != null && projects.Length > 0)
{
// Get the first project's ID
int firstProjectId = projects[0].Id;
Console.WriteLine($"First Project ID: {firstProjectId}");

// Use the project ID to fetch the project estates
string estatesEndpointWithId = $"/public/projects/{firstProjectId}/estates";

HttpResponseMessage estatesResponse = await client.GetAsync(estatesEndpointWithId);
estatesResponse.EnsureSuccessStatusCode();

// Display estates data
string estatesData = await estatesResponse.Content.ReadAsStringAsync();
Console.WriteLine($"First Project Estates: {estatesData}");
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Request error: {ex.Message}");
}
}
}
}

// Define class matching the JSON structure (see https://api.innobrix.net/api/v1.1/)
public class Project
{
public int Id { get; set; }
public string Name { get; set; }
public string License { get; set; }
}