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:
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
Glad it worked, i think i have suggested that, but anyways enjoy the solution!
Cheers!