> ## Documentation Index
> Fetch the complete documentation index at: https://docs.junction.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate a link token

> Create or submit link token via the Junction API. Requires authentication with your team API key.

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
       --url {{BASE_URL}}/v2/link/token \
       --header 'Accept: application/json' \
       --header 'Content-Type: application/json' \
       --header 'x-vital-api-key: <API_KEY>' \
       --data '
  {
       "user_id": "1875c190-0cd6-46c1-8670-5b56a7794b78"
  }
  '
  ```

  ```typescript TypeScript theme={null}
  import { JunctionClient, JunctionEnvironment } from "@junction-api/sdk";

  const client = new JunctionClient({
      apiKey: "YOUR_API_KEY",
      environment: JunctionEnvironment.Sandbox,
  });

  const data = await client.link.token({
      userId: "<user_id>",
      provider: "oura",
  });
  ```

  ```python Python theme={null}
  from junction import Junction, Providers
  from junction.environment import JunctionEnvironment

  client = Junction(
      api_key="YOUR_API_KEY",
      environment=JunctionEnvironment.SANDBOX,
  )

  data = client.link.token(user_id="<user_id>", provider=Providers.OURA)
  ```

  ```java Java theme={null}
  import com.junction.api.Junction;
  import com.junction.api.core.Environment;
  import com.junction.api.resources.link.requests.LinkTokenExchange;
  import com.junction.api.types.Providers;

  Junction client = Junction.builder()
      .apiKey("YOUR_API_KEY")
      .environment(Environment.SANDBOX)
      .build();

  var data = client.link().token(
      LinkTokenExchange.builder()
          .userId("<user_id>")
          .provider(Providers.OURA)
          .build()
  );
  ```

  ```go Go theme={null}
  import (
      "context"

      junction "github.com/junction-api/junction-go"
      "github.com/junction-api/junction-go/client"
      "github.com/junction-api/junction-go/option"
  )

  c := client.NewClient(
      option.WithApiKey("YOUR_API_KEY"),
      option.WithBaseURL(junction.Environments.Sandbox),
  )

  provider := junction.ProvidersOura
  response, err := c.Link.Token(context.TODO(), &junction.LinkTokenExchange{
      UserId:   "<user_id>",
      Provider: &provider,
  })
  if err != nil {
      return err
  }
  fmt.Printf("Received data %s\n", response)
  ```
</RequestExample>


## OpenAPI

````yaml POST /v2/link/token
openapi: 3.1.0
info:
  title: Junction API
  description: https://docs.junction.com/
  version: 0.4.495
servers:
  - url: https://api.us.junction.com
    x-fern-server-name: Production
  - url: https://api.eu.junction.com
    x-fern-server-name: ProductionEU
  - url: https://api.sandbox.us.junction.com
    x-fern-server-name: Sandbox
  - url: https://api.sandbox.eu.junction.com
    x-fern-server-name: SandboxEU
security:
  - apiKeyAuth: []
paths:
  /v2/link/token:
    post:
      tags:
        - link
      summary: Generate Vital Link Token
      description: |-
        Endpoint to generate a user link token, to be used throughout the vital
        link process. The vital link token is a one time use token, that
        expires after 10 minutes. If you would like vital-link widget to launch
        with a specific provider, pass in a provider in the body. If you would
        like to redirect to a custom url after successful or error connection,
        pass in your own custom redirect_url parameter.
      operationId: generate_vital_link_token_v2_link_token_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LinkTokenExchange'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LinkTokenExchangeResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    LinkTokenExchange:
      properties:
        user_id:
          type: string
          format: uuid
          title: User Id
          description: >-
            User id returned by vital create user request. This id should be
            stored in your database against the user and used for all
            interactions with the vital api.
        provider:
          anyOf:
            - $ref: '#/components/schemas/Providers'
            - type: 'null'
          description: ℹ️ This enum is non-exhaustive.
        redirect_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Redirect Url
        filter_on_providers:
          anyOf:
            - items:
                $ref: '#/components/schemas/Providers'
              type: array
              minItems: 1
            - type: 'null'
          title: Filter On Providers
          description: >-
            An allowlist of providers dictating what Vital Link Widget should
            show to the end user.

            If unspecified, all linkable providers are shown.


            This has no effect on programmatic Vital Link API usage.
        on_error:
          anyOf:
            - type: string
              const: redirect
            - type: 'null'
          title: On Error
          description: >-
            By default, Vital Link Widget input forms for password and email
            providers have in-built error handling.


            Specifying `on_error=redirect` disables this Vital Link Widget UI
            behaviour — it would

            instead redirect to your `redirect_url`, with Link Error parameters
            injected.


            This has no effect on OAuth providers — they always redirect to your
            `redirect_url`. This also has

            no effect on programmatic Vital Link API usage.
        on_close:
          anyOf:
            - type: string
              const: redirect
            - type: 'null'
          title: On Close
          description: >-
            By default, Vital Link Widget closes the window or tab when the user
            taps the Close button.


            Specifying `on_close=redirect` would change the Close button
            behaviour to redirect to your `redirect_url`

            with the `user_cancelled` error specified.


            This has no effect on programmatic Vital Link API usage.
      type: object
      required:
        - user_id
      title: LinkTokenExchange
    LinkTokenExchangeResponse:
      properties:
        link_token:
          type: string
          title: Link Token
          description: >-
            A short-lived Vital Link token for your Custom Link Widget to
            communicate with the Vital API.
        link_web_url:
          type: string
          title: Link Web Url
          description: >-
            The web browser link to launch the default Vital Link experience. If
            you requested the token for one specific provider, the link would
            redirect directly to the provider authentication flow. Otherwise,
            the user would be presented with a list of providers based on your
            team and token configurations.
      type: object
      required:
        - link_token
        - link_web_url
      title: LinkTokenExchangeResponse
      example:
        link_token: dGVzdCB0ZXN0IHRlc3Q=
        link_web_url: >-
          https://link.tryvital.io/?token=dGVzdCB0ZXN0IHRlc3Q%3D&env=production&region=us
    HTTPValidationError:
      properties:
        detail:
          title: Detail
      type: object
      title: HTTPValidationError
    Providers:
      type: string
      enum:
        - oura
        - fitbit
        - garmin
        - whoop
        - strava
        - renpho
        - peloton
        - wahoo
        - zwift
        - freestyle_libre
        - abbott_libreview
        - tandem_source
        - freestyle_libre_ble
        - eight_sleep
        - withings
        - apple_health_kit
        - manual
        - ihealth
        - google_fit
        - beurer_api
        - beurer_ble
        - omron
        - omron_ble
        - onetouch_ble
        - accuchek_ble
        - contour_ble
        - dexcom
        - dexcom_v3
        - hammerhead
        - my_fitness_pal
        - health_connect
        - samsung_health
        - polar
        - cronometer
        - kardia
        - whoop_v2
        - ultrahuman
        - my_fitness_pal_v2
        - map_my_fitness
        - runkeeper
      title: Providers
      description: ℹ️ This enum is non-exhaustive.
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-vital-api-key
      description: Vital Team API Key

````