Getting started with integrating the Tripletex API into the Microsoft 365 world!

This is the start of a series of blog posts, where our end goal is to take data from the Tripletex API to create insightful reports, store it in Teams Dataverse, and at last visualize the reports in PowerBI. Today we are starting by looking at how you set up the API access in Tripletex and how you interact with it by using PowerShell.

First, we need to activate the API access in Tripletex. This you can do under the menu “Company -> My Subscription”. Click Order Integration under the Integration part.

You should get an application name and consumer token from Tripletex Support by email that you need for authentication.

After the API integration is set up, you should be able to see a tab named API-access on all employee pages. Go to this menu on the user page for the person that’s going to use the API integration. We need to create an Employee token, which is the user’s personal key to authenticate against the Tripletex API.

Click “New key”.

Choose the application name you got from support.

Check the “Custom setup” box, and select the access needed. In this blog post series, I’m using the “All rights” choice.

Click “Create Key”.

Now a box with the Employee token will appear. Take note of this, as you won’t see it after you click OK.

For a more in-depth description of the steps above in Norwegian, take a look here.

The next step is to take a look at how we communicate with the API by using PowerShell. Here you can find information about the Tripletex API, but there was no info on how to authenticate. I looked through the public GitHub repo for Tripletex, and here I found an example using Bash on how I could authenticate. Next was just some small adjustments for PowerShell as most API calls are like no matter which “language” you use.

This is the PowerShell “code” for generating the authorization token and adding it to the header you will use in the API calls.

$consumerToken = "Enter your consumer token here"
$employeeToken = "enter your employee token here"
#Expiration date of the authorization toke you generate is set to 1 day from now.
$expirationDate = get-date ((get-date).Adddays(+1)) -format "yyyy-MM-dd"
$uri = "$consumerToken&employeeToken=$employeeToken&expirationDate=$expirationDate"
#Get token and create header.
$token = ((Invoke-RestMethod -Method PUT -Uri $uri -ContentType "application/JSON").value).token
$user = '0'
$pass = $token
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$Header = @{"Authorization" = "Basic $encodedCreds"}

Now that we have an authorization token, we can start doing some API calls. Lets take a look at the API docs you can find here, and see which endpoints we can call. Lets use Projects as an example. We want to list all projects we currently have in Tripletex. We scroll until we see Project, and expand it.

Here we see a call called GET /project. Click it.

The great thing about this API documentation is that its interactive and help you generate the URL you need to call. So click “Try it out”. Now you can fill inn lots of difrent parameters to filter your search, but we want all of the projects, so scroll down until you see the field “Count”, and clear it. Then you can click “Execute”.

Now you can see the “Request URL”, and this is what we need for doing our API call in PowerShell.

Here is the PowerShell “code” to do the API call and use the header we created above.

$ProjectsURL = ""
$Projects = (Invoke-RestMethod -Method Get -uri $ProjectsURL -Headers $Header).values

If you now output $Projects, and take a look at what properties a object have, you can see a lot of interesting information. You also see that for example inside the “participants” property, you see a list of IDs/URLs. This means you need to do an API call against the participant endpoint, to get info on the participant.

Here you see the output of the participant API call. Again, you see only IDs. You have to do one more call against the employee endpoint to the actual name of the project participant. (You see in the code for the Projects call that it says “).values”, if there is only one object, like with the participants call, it would be “).value” instead.)

You see, there are a lot of API calls needed to the done and looped through to get all details on for example a project. In the next post in this series, il go more into depth on how to do all that logic around doing multiple calls/loops to get the information you need.

One thought on “Getting started with integrating the Tripletex API into the Microsoft 365 world!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s