How do I create HTTP header auth credentials via API?

I used to create HTTP Header Auth credentials via API up until today. Now it shows errors. The payload I send is:
{
“name”: “Test Creds”,
“type”: “httpHeaderAuth”,
“data”: {
“name”: “Authorization”,
“value”: “testtest”
}
}

Describe the problem/error/question

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 @valonn Welcome!
This is strange, have you created credential schema endpoint before and then built your payload from that?? something like GET /api/v1/credentials/schema/httpHeaderAuth so that you could get the exact data structure it needs for that header auth, maybe then you can try sending that POST request POST /api/v1/credentials with your name on it, and type “httpHeaderAuth” , and so your data object matches this schema, although i think you must be following this so if not let me know how this goes…

2 Likes

POST /api/v1/credentials

{
“name”: “Test Creds”,
“type”: “httpHeaderAuth”,
“data”: {
“json”: { ///////// n8n stores credential values inside the json object /////////////
“name”: “Authorization”,
“value”: “testtest”
}
}
}

2 Likes

Thank you. This helped me solve the issue. I think “allowedHttpRequestDomains” wasn’t required before.

2 Likes

Glad it helped @valonn consider marking that as a solution! Cheers!

1 Like

@alliance got it right. the json wrapper is the thing most people miss. if youre creating multiple credential types programmatically, fetching the schema first via GET /api/v1/credentials/schema/{type} saves you having to guess the structure each time.

1 Like

@alliance nailed it — the "json" wrapper is the key. n8n internally stores all credential data under a json property, so you need "data": { "json": { "name": "...", "value": "..." } } instead of flat data. One tip: if you’re creating multiple credential types programmatically, always fetch the credential schema first via GET /api/v1/credentials/schema/{type} — saves guessing the exact structure each time.

2 Likes

Thanks for your reply.

That will help my work in the next time.

Thanks again.

1 Like

@alliance nailed it — the "json" wrapper is the key. n8n internally stores all credential data under a json property, so you need "data": { "json": { "name": "...", "value": "..." } } instead of flat data. One tip: if you’re creating multiple credential types programmatically, always fetch the credential schema first via GET /api/v1/credentials/schema/{type} — saves guessing the exact structure each time.