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
- C-Sharp (C#)
- Python
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; }
}
application.py
import requests
import json
# Base-URL of the API
BASE_URL = "https://api.innobrix.net/api/v1.1"
# Endpoint for retrieving the projects
PROJECT_ENDPOINT = "/public/projects"
# Bearer-token used for authorization (replace this with your API key)
BEARER_TOKEN = "API Key"
# Configure the headers
headers = {
"Authorization": f"Bearer {BEARER_TOKEN}",
"Content-Type": "application/json"
}
def get_projects():
try:
response = requests.get(BASE_URL + PROJECT_ENDPOINT, headers=headers)
response.raise_for_status()
projects_data = response.json()
print(f"Projects: {json.dumps(projects_data, indent=2)}")
return projects_data
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
return None
def get_estates(project_id):
try:
estates_endpoint = f"/public/projects/{project_id}/estates"
response = requests.get(BASE_URL + estates_endpoint, headers=headers)
response.raise_for_status()
estates_data = response.json()
print(f"First Project Estates: {json.dumps(estates_data, indent=2)}")
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
if __name__ == "__main__":
projects = get_projects()
if projects and len(projects) > 0:
first_project_id = projects[0]['id']
print(f"First Project ID: {first_project_id}")
get_estates(first_project_id)