How do I get my n8n flow to reach my foundry agent via API access

I am trying to pass the email body and subject to a published MS Foundry agent to have it make a decision on whether the email is an order or not, but am unable to get to the agent via API and have no clue whether there is another method that would be more suited to my needs

Describe the problem/error/question

Consistently getting a 401 error which I have narrowed down to either the API key or the endpoint

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

[

{

“body”:
{

“error”:
{

“code”:
“401”,

“message”:
“Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.”

}

},

“headers”:
{

“content-length”:
“224”,

“connection”:
“close”,

“content-type”:
“application/json”,

“date”:
“Wed, 11 Mar 2026 01:30:24 GMT”,

“apim-request-id”:
“98025f0b-c5c4-4d23-ad4d-48f375db4ceb”

},

“statusCode”:
401,

“statusMessage”:
“PermissionDenied”

}
]

Information on your n8n setup

  • n8n version: 1.123.22
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloud
  • Operating system: Win 11

Hi @JamesCMS Welcome!
I recommend moving your api-key from query parameters to the send headers section of the HTTP request node, so that it fulfills the azure requiring a API key as a header not that URL you are currently sending.

I have done so but I still have the same error.

Output

1 item

[

{

“body”: {

“error”: {

“code”: “401”,

“message”: “Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.”

}

},

“headers”: {

“content-length”: “224”,

“connection”: “close”,

“content-type”: “application/json”,

“date”: “Wed, 11 Mar 2026 21:08:14 GMT”,

“apim-request-id”: “d3df57b8-e799-4431-801d-420e2f6eef16”

},

“statusCode”: 401,

“statusMessage”: “PermissionDenied”

}

]

Curl gives me the below error text, no object ID though, this leads me to believe the API endpoint is correct but the permissions on the resource are incorrect somehow

Identity(object id: ) does not have permissions for Microsoft.MachineLearningServices/workspaces/agents/action actions. Please refer to Manage roles in your workspace - Azure Machine Learning | Microsoft Learn to fix the permissions issue.

Hi @Benjamin_Behrens - I am getting a 401 error which I am currently assuming is an RBAC permissions error on the Azure side, but without the object ID I cannot narow it dow, even using curl I got a blank object ID.

Changing to “bearere” from “api-key” didnt change anything FYI

@Benjamin_Behrens That makes a lot of sense, still getting a 401 with the regenerated API key - the previous key was definitely from the correct resource also. I am new at this so it could also be the endpoint isn’t right, but from all the documentation I have read it should be.

I am back to being sus on the endpoint I am trying to hit. I’ll go read some more documentation as from what I have read the published agent should be reachable, the below were the endpoints supplied by Foundry on publishing the agent, 401 errors also

@Benjamin_Behrens The API auth option is under properties at the resource level and is already enabled, good idea to check for sure.

I’ll come back to the rest tomorrow and let you know.

Hey a colleague has found a solution, needed to create a generic credential with the API key, change the auth type on the HTTP request to generic header auth and direct to the responses endpoint, completed solution pasted in below

{
“nodes”: [
{
“parameters”: {
“pollTimes”: {
“item”: [
{
“mode”: “everyMinute”
}
]
},
“output”: “raw”,
“filters”: {},
“options”: {
“attachmentsPrefix”: “attachment_”,
“downloadAttachments”: true
}
},
“type”: “n8n-nodes-base.microsoftOutlookTrigger”,
“typeVersion”: 1,
“position”: [
-16,
224
],
“id”: “361daf1c-4049-487c-9c6c-872efa463c6c”,
“name”: “Microsoft Outlook Trigger”,
“credentials”: {
“microsoftOutlookOAuth2Api”: {
“id”: “QK6tJproo2mXU4kP”,
“name”: “aiagent@adxdepot.com.au”
}
}
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://n8n-order-email-to-myob-resource.services.ai.azure.com/api/projects/n8n_order_email_to_myob/applications/IsEmailAnOrder/protocols/openai/responses?api-version=2025-11-15-preview”,
“authentication”: “genericCredentialType”,
“genericAuthType”: “httpHeaderAuth”,
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: "={\n “model”:“gpt-5-nano”,\n “input”: [\n {“role”: “user”, “content”: “Get an answer”}\n ]\n} ",
“options”: {
“response”: {
“response”: {
“fullResponse”: true,
“neverError”: true
}
}
}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.3,
“position”: [
304,
224
],
“id”: “fa35b8c7-3af3-4e16-9e22-bb449f5c27f0”,
“name”: “HTTP Request”,
“alwaysOutputData”: false,
“credentials”: {
“httpHeaderAuth”: {
“id”: “sBG16iYZ17SvUH5B”,
“name”: “n8n-order-email-to-myob-resource API key 1”
}
}
}
],
“connections”: {
“Microsoft Outlook Trigger”: {
“main”: [
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
},
“HTTP Request”: {
“main”: [

]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “0fc75bd7dd2d50f89302cfdf6389f85b36fccf740504f34cbd68bd897bb95280”
}
}