Do we have any doc for N8N REST APIs

Describe the problem/error/question

We are trying to update the Credential via REST, but the data is not getting reflected.

Invoke-RestMethod `

-Method PATCH `
-Uri "$n8nUrl/api/v1/credentials/$credentialId" `
-Headers @{
    "X-N8N-API-KEY" = $apiKey
    "Content-Type"  = "application/json"
} `
-Body $body

$body = @{

data = $tokenResponse.Token
} | ConvertTo-Json -Depth 5

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

Hi @shakthipsg!
Your body is sending data as a plain string (the token value directly), but the API expects data to be a JSON object with the appropriate credential fields, not a raw string value.

The PATCH /credentials/{id} endpoint expects this structure: [API Docs]

{
“data”: {
“accessToken”: “your_new_token_value”
}
}

The data field must be an object containing the credential’s named properties (accessToken, not the token value directly).

powershell
$body = @{
data = @{
accessToken = $tokenResponse.Token
}
isPartialData = $true
} | ConvertTo-Json -Depth 5

Invoke-RestMethod
-Method PATCH
-Uri “$n8nUrl/api/v1/credentials/$credentialId”
-Headers @{
“X-N8N-API-KEY” = $apiKey
“Content-Type” = “application/json”
}
-Body $body

Ensure your header is named exactly X-N8N-API-KEY, this is a common source of unauthorized errors. [API Authentication]

We have already tried the same body content, but

Invoke-RestMethod : {“message”:“request.body.data is not allowed to have the additional property “accessToken””}

Hi @shakthipsg Actually we do have a documentation but it is not quite aware of common errors and more problems:

And consider using this structure because the issue currently is with body and how you are structuring it consider trying this:

$body = @{
    data = @{
        accessToken = $tokenResponse.Token  # use the actual field name for your credential type
    }
    isPartialData = $true  # merges with existing data instead of replacing everything
} | ConvertTo-Json -Depth 5

Invoke-RestMethod `
    -Method PATCH `
    -Uri "$n8nUrl/api/v1/credentials/$credentialId" `
    -Headers @{
        "X-N8N-API-KEY" = $apiKey
        "Content-Type"  = "application/json"
    } `
    -Body $body

@Anshul_Namdev
The snippet gives the same error

Invoke-RestMethod : {“message”:“request.body.data is not allowed to have the additional property “accessToken””}

This worked for Credential type ‘Bearer Auth‘

$body = @{

data = @{
    token = $tokenResponse.Token
}
isPartialData = $true

} | ConvertTo-Json -Depth 5

1 Like

Glad it worked, i think i have suggested that, but anyways enjoy the solution!

Cheers!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.