This feature is in preview. The API may change before general availability. To try it out, contact support@intunedhq.com and we’ll enable it for your workspace.
IntunedClient from @intuned/client) for the workspace your automation runs in. Use it to start Runs of any Project in the workspace from inside an automation and read their results, without putting an API key in your code.
Inside a Run, the client authenticates with the Run’s own token and reads it again on every request, so a refreshed token is always used. Outside a Run, for example with the CLI on your machine, it uses INTUNED_API_KEY, or INTUNED_AUTH_TOKEN when there is no API key.
Install
getIntunedClient needs @intuned/client 1.2.0 or later in your Project. It’s an optional dependency of @intuned/runtime, so Projects that don’t use it never load it.
@intuned/runtime/client, not from @intuned/runtime.
Parameters
Optional settings for the client.
GetIntunedClientOptions
The workspace to call. Defaults to the workspace the automation runs in.
Inside a Run, only that workspace is allowed.
Log each request instead of sending it.
true logs it with console.log. A
function receives each request instead. Credentials are masked. Client methods
then resolve to undefined. Recommended in the IDE and the local CLI.Returns
APromise<IntunedClient>. The client has the same methods as one you create yourself, for example client.projects.runs.start() and client.projects.runs.result(). See the Run API reference.
Throws
- When
@intuned/clientisn’t installed, or is older than 1.2.0, with the command to install or upgrade it. - Inside a Run, when
workspaceIdnames another workspace. - In AuthSession
createandcheckfunctions. Call it from an API instead. - When it has no credentials or can’t tell which workspace to call. With the CLI, run
intuned provisionfirst.
What a Run can call
Inside a Run, the client can call two operations, on any Project in the workspace:
Every other operation, such as canceling a Run or managing Jobs and AuthSessions, fails with
401 inside a Run. Outside a Run, the client can call everything your API key allows.
Runs started from a Run
Inside a Run,client.projects.runs.start() does three things for you:
- Links the new Run to this one. The new Run records this Run as its parent and the first Run of the chain as its root. Run details show who started it, with links to the parent and root Runs, and the parent’s Run details list it under Child Runs. The Run result’s
metadatahasparentRunIdandrootRunId. - Passes on this Run’s attributes. The new Run starts with this Run’s current attributes, including ones set earlier in this Attempt. Attributes you pass in the request body override them by key.
- Makes retries safe. Without an
idempotencyKey, the client derives one from this Run’s ID and the request. When an Attempt fails and the next Attempt starts the same Run again, it gets the first Run back instead of starting a second one. See Idempotency keys.
runs.start() calls in the same Run return the same Run. To start several Runs with the same request, give each one its own idempotencyKey.
A chain of Runs starting Runs can be at most 10 deep. The Run at depth 10 gets a 403 if it tries to start another one.
In the IDE, Runs started this way aren’t linked as child Runs and get no
default idempotency key.