Skip to content

Connecting to the API ​

A plain-English guide for whoever is connecting a tool to hidma, whether that is you, an IT provider or a developer. It explains the ideas behind the API and what to expect. The exact calls, with examples you can try, are in the API documentation, which opens from Settings › API Access.

You will need

  • An application set up in Settings › API Access, with its client ID, client secret and workspace ID. See Setting up API access.
  • A tool that can send web requests, such as Postman, Power BI, curl, or your own code.

The words you will see ​

WordWhat it means
ApplicationThe record in hidma that stands for your tool. It holds what the tool is allowed to do.
Client IDThe application's username. Starts with app_.
Client secretThe application's password. Keep it on a server, never in a web page or a shared file.
Workspace IDWhich hidma workspace a request is for. Sent with every request in the X-Hidma-Tenant-Id header.
Access tokenA pass the tool gets by sending its client ID and secret. It lasts 60 minutes and is sent with every request.
Refresh tokenA second pass, which lasts 30 days, used to get a new access token without sending the secret again.
ScopeOne permission, such as clients:read. The access you chose for the application becomes a list of scopes.

How a connection works ​

  1. Get a token. The tool sends its client ID and secret to hidma's token address. hidma checks them and sends back an access token.
  2. Make requests. For each request, the tool sends the access token and the workspace ID. hidma checks the token is valid and allows that area, then answers.
  3. Get a new token before the hour is up. The tool either repeats step 1 or uses the refresh token.

The token address and an example request are shown in the window that appears when you create the application, under How to get a token, and at the top of the API documentation.

Access levels and scopes ​

The levels you chose in Settings › API Access turn into scopes on the token:

AreaRead onlyRead and write
Clientsclients:readclients:read and clients:write
Projectsprojects:readprojects:read and projects:write
Jobsjobs:readjobs:read and jobs:write
Timesheetstimesheets:readtimesheets:read and timesheets:write
Usersusers:readNot available. Users are read only.

If the tool tries something its application is not allowed, hidma refuses with an insufficient_scope error. The fix is to change the application's access in hidma, not the tool.

What the API can do today ​

AreaCalls available
ClientsList clients, view a client, add a client, update a client
ProjectsList projects, view a project
JobsList jobs, view a job
TimesheetsList weekly timesheets, view a timesheet
Time entriesList time entries, view one, add one, change one, delete one
UsersList users, view a user

Lists come back a page at a time rather than all at once. Time entries can be filtered by person, project, job and date range. Users can be filtered by email address or team.

Each user comes back with their name, email address, job title, team and whether they are active. Users cannot be added or changed through the API; do that in hidma under Users.

Logging time through the API ​

A time entry is one piece of time: who did it, on which job, on which day, and for how long. It is the single call for logging time. You do not need to create a weekly timesheet first, because hidma finds or creates the right timesheet and row for you.

Each time entry needs:

DetailNotes
PersonThe user the time belongs to. If your other system knows people by email, look up their hidma user by email first (this needs Read only on Users).
JobThe job the time was spent on. A project can also be given.
DateThe day the work was done
MinutesHow long, in minutes. 90 means an hour and a half.
CommentsOptional. What was done.
Non-billable minutesOptional. How much of the time should not be billed. Cannot be more than the total minutes.

hidma protects time that has already moved on:

  • Time cannot be added to a timesheet that has been approved. The API refuses with timesheet_approved. Unapprove the timesheet in hidma first if the time really needs adding.
  • A time entry that has already been billed or written off cannot be changed. The API refuses with entry_already_billed.

This is the same protection you get when entering time in hidma itself. See Timesheet Approval.

Limits ​

LimitWhat it means
60 requests a minutePer application, across all its workspaces
5 requests at the same timePer application, across all its workspaces
30 token requests a minutePer internet address, for getting and cancelling tokens

If the tool goes over, hidma replies with 429 and says how many seconds to wait in the Retry-After header. Every reply also says how many requests are left this minute, in the X-MinLimit-Remaining header.

Reuse the token

Get a token once and reuse it until it is nearly an hour old. Asking for a new token before every request wastes your limit and slows the tool down.

Keeping the token fresh ​

An access token stops working after 60 minutes. When that happens, requests fail with 401. The tool can then either:

  • Start again by sending the client ID and secret, which is the simplest option, or
  • Use the refresh token, which lasts 30 days.

Each time a refresh token is used, hidma sends back a new access token and a new refresh token. The tool must keep the new refresh token and throw away the old one.

A refresh token works once

If a used refresh token is sent again more than 5 minutes later, hidma treats it as stolen and cancels every token made from it. The tool then has to start again with the client ID and secret.

When a user disconnects your tool, it can cancel its own tokens by sending them to hidma's revoke address. The API documentation shows how.

When something goes wrong ​

Every error comes with a short code and a plain description. The common ones:

CodeWhat happenedWhat to do
invalid_clientThe client ID or secret is wrong, or the application is turned offCheck the details. In hidma, check the application is Active.
invalid_tokenThe access token has run out or is wrongGet a new token
tenant_requiredThe request did not say which workspaceSend the workspace ID in the X-Hidma-Tenant-Id header
tenant_not_grantedThe application cannot use that workspaceAdd the workspace to the application in hidma
insufficient_scopeThe application is not allowed to do thisChange its access in Settings › API Access
invalid_scopeThe tool asked for more than the application is allowedAsk for less, or change the application's access
invalid_grantThe refresh token has been used, has run out or was cancelledStart again with the client ID and secret
timesheet_approvedThe time is for a week whose timesheet is approvedUnapprove the timesheet in hidma, or log the time elsewhere
entry_already_billedThe time entry has been billed or written offLeave it, or reverse the bill in hidma first
429Too many requestsWait the number of seconds in Retry-After, then try again

Application suddenly turned off?

After 10 wrong secrets in 5 minutes, hidma turns the application off to protect your data. Fix the secret in your tool, then turn the application back on in Settings › API Access.

Trying it out in the API documentation ​

The API documentation lets you try each call from your browser:

  1. Open it from the API documentation button in Settings › API Access. You need to be signed in to hidma.
  2. Click Authorize at the top and enter the client ID and client secret. Leave the scopes unticked to get everything the application is allowed.
  3. On any call, click Try it out, enter your workspace ID in X-Hidma-Tenant-Id, and send it.

These are real requests

Trying a call in the documentation works on your real hidma data. Anything you add, change or delete there is added, changed or deleted in your workspace.

hidma Help Centre