---
title: "POST Get valid credentials for a connection, refreshing OAuth tokens if needed."
description: "Used by scheduled jobs to ensure tokens are valid before running checks."
last_updated: "2026-05-06T07:33:47.988203+00:00"
canonical_url: "https://www.doc0.dev/docs/49c89830-117b-4def-8edc-b5bcc50766e0/api/connections/ensurevalidcredentials"
---

<APIEndpoint
  method={"POST"}
  path={"/integrations/connections/:id/ensure-valid-credentials"}
  summary={"Get valid credentials for a connection, refreshing OAuth tokens if needed."}
  description={"Used by scheduled jobs to ensure tokens are valid before running checks."}
  deprecated={false}
  baseUrl={""}
/>

## Parameters

<APIParameters parameters={[{"name":"id","in":"path","required":true,"description":"The ID of the connection","schema":{"type":"string"}},{"name":"organizationId","in":"query","required":true,"description":"The ID of the organization","schema":{"type":"string"}}]} />

## Responses

<APIResponse
  statusCode={"201"}
  description={"Valid credentials"}
  contentType={"application/json"}
  schema={{"type":"object"}}
/>

<APIResponse
  statusCode={"400"}
  description={"Bad request (e.g., organizationId required, connection not active, no credentials found)"}
  contentType={"application/json"}
  schema={{"type":"object"}}
/>

<APIResponse
  statusCode={"401"}
  description={"Token refresh failed. Please reconnect the integration."}
  contentType={"application/json"}
  schema={{"type":"object"}}
/>

<APIResponse
  statusCode={"404"}
  description={"Connection or provider not found"}
  contentType={"application/json"}
  schema={{"type":"object"}}
/>

## Try It

<APIPlayground
  method={"POST"}
  path={"/integrations/connections/:id/ensure-valid-credentials"}
  parameters={[{"name":"id","in":"path","required":true,"description":"The ID of the connection","schema":{"type":"string"}},{"name":"organizationId","in":"query","required":true,"description":"The ID of the organization","schema":{"type":"string"}}]}
  baseUrl={""}
/>


## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/49c89830-117b-4def-8edc-b5bcc50766e0/llms.txt) for all pages in this wiki.
