Tips and Tricks for API v3

API v3 introduces new functionality that can help you write smarter, faster, and more efficient integrations. Here are some practical tips and advanced features you can start using today.

Use $expand to load related data in one call

The $expand parameter lets you fetch related data in a single request—reducing the number of API calls you need to make and simplifying your code.

Example

Instead of making separate requests to get an employee and their department:

GET https://api.tidsbanken.net/ansatt/ansatt?$select=Id,fornavn,etternavn,avdelingid
GET https://api.tidsbanken.net/ansatt/avdeling?$select=id,navn

You can get both at once:

GET https://api.tidsbanken.net/ansatt/ansatt?$select=Id,fornavn,etternavn,avdelingid&$expand=avdeling

This returns the employee and their department in one response.

You can also expand multiple relationships and combine with $select:

GET https://api.tidsbanken.net/prosjekt/Prosjekt?$select=id,navn,avdelingid,anleggid&$expand=avdeling($select=id,navn),anlegg($select=id,navn)

This is especially useful when displaying overviews, dashboards, or lists where related information is needed right away.

What is an “Aggsert”? Understanding AggsertOmsetning

The word Aggsert is a combination of Aggregate + Insert. It's a special operation available in some APIs—like AggsertOmsetning—that allows you to either update an existing row with new totals or insert a new row if none exists.

Here’s how it works behind the scenes:

  1. Search for an existing row
    The system checks if a row already exists with a matching combination of values (e.g., date + department ID).

  2. If the row exists
    The values are updated—typically by adding to the existing totals (e.g., add to total revenue, increment sales count).

  3. If the row does not exist
    A new row is created with the provided data, initializing the totals and setting the context (e.g., date, department, type).

Why it's useful:

With AggsertOmsetning, you don’t have to check if a record already exists before updating it. The logic is built-in—making it easier to build robust import flows, synchronizations, or periodic data updates.

Example Use Case:

You want to report daily sales per department. Every time a sale is posted:

  • If a matching row exists (for that department and date), you update the total.

  • If not, you create a new entry for that day and department.