# Connecting to systems that require OAuth
URL: https://docs.awellhealth.com/docs/connect-systems/oauth-client-credentials

> For the complete documentation index, see [llms.txt](https://docs.awellhealth.com/llms.txt).



Many systems require OAuth2 rather than a static API key, which means fetching an access token from the
authorization server before calling the actual API with it.

A care flow models this as **two API call actions in sequence**.

## What's needed first [#whats-needed-first]

* The credentials to authorize with the authorization server: a **client ID** and **client secret**.
* Working knowledge of [API call actions](/docs/connect-systems/the-api-call-action-graphql-and-rest)
  and OAuth2.

## Step 1: Fetch an access token [#step-1-fetch-an-access-token]

1. **Find the token endpoint.** Check the system's documentation or ask their administrator for the URL
   that issues tokens.
2. **Make a POST request** to it with an API call action, sending the client ID and client secret as the
   client credentials grant expects.
3. **Store the token in a data point** using JSON path on the response.

Keep the client ID and secret in
[constants](/docs/connect-systems/store-static-values-in-constants), not typed into the action.

## Step 2: Use the access token [#step-2-use-the-access-token]

Add a second API call action for the real request, and pass the stored token in the `Authorization`
header as a [variable](/docs/design-care-flows/use-variables-in-your-actions).

The two actions must run in order, so put them in sequence in the same step or in consecutive steps.

## Tokens expire [#tokens-expire]

An access token has a lifetime. A care flow that fetches a token and then calls the API days later finds
it expired.

Fetch the token immediately before the call that uses it, rather than once at the start of a long flow.
Where a flow makes several calls over time, each needs its own fresh token.

## Next steps [#next-steps]

For a worked example against a real vendor, see
[setting up a GraphQL API call to Healthie](/docs/connect-systems/healthie-graphql-api-call).
