Custom body credentials multiple levels down in JSON body of HTTP Request to Odoo

Describe the problem/error/question

I need to send a custom (or unavailable) Odoo command via JSONRPC to my Odoo instance. So I’m using an HTTP Request to do so. However, because Odoo requires the password or API key multiple levels deep in the body JSON, I’m not able to use one of the Generic Type credentials.

{
	"jsonrpc": "2.0",
	"method": "call",
	"params": {
		"service": "object",
		"method": "execute",
		"args": [
			"{{ $json.odoo_database_name }}",
			{{ $json.odoo_user_id }},
			"{{ $json.odoo_api_key }}",
			"account.move",
			"action_post",
			[
				{{ $('Merge').first().json.id }}
			]
		]
	},
	"id": {{ Math.floor(Math.random() * 1000000000) }}
}

I checked the {{ $parameter }} object, but I can’t reference my custom auth object or any other generic one.

Does anyone know how I can reference a generic credentials object to replace the {{ $json.odoo_api_key }} expression above?

What is the error message (if any)?

Invalid credentials

Information on your n8n setup

  • n8n version: 1.99.1
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker container in AWS ECS
  • Operating system: OS used by stable tag at https://hub.docker.com/r/n8nio/n8n/tags

Hello @erockx ,

I’m not sure I fully understand the issue, but in general, the pattern is that the fields you’re referencing in your expression need to be present in the incoming item.


Here’s an example workflow:

When credentials are used normally, their values are not present in the input or output data. That’s the functionality I’m trying to get here.

When I create a Custom Auth Generic Credential, I have to use this JSON format:

{
  "body": {
    "apikey": "api_key_value"
  }
}

However, that doesn’t put the value in the correct place in my JSON payload for the Odoo API call. I believe it does the following:

{
	"jsonrpc": "2.0",
	"method": "call",
	"params": {
		"service": "object",
		"method": "execute",
		"args": [
			"{{ $json.odoo_database_name }}",
			{{ $json.odoo_user_id }},
			"{{ $json.odoo_api_key }}",
			"account.move",
			"action_post",
			[
				{{ $('Merge').first().json.id }}
			]
		]
	},
	"id": {{ Math.floor(Math.random() * 1000000000) }},
	"apikey": "api_key_value"
}

When I actually want n8n to be able to insert the value deeper in my JSON object. I realize that inserting a credential into a specific element of a list is probably too much. Fortunately, Odoo allows for keyword arguments, so I’d like to be able to create this custom auth generic credential:

{
  "body": {
    "params": {
      "args": {
        "password": "api_key_value"
      }
    }
  }
}

And have that key/value pair be automatically added to the payload below inside params and args objects, respectively.

{
	"jsonrpc": "2.0",
	"method": "call",
	"params": {
		"service": "object",
		"method": "execute_kw",
		"args": {
			"database": "{{ $json.odoo_database_name }}",
			"user_id": {{ $json.odoo_user_id }},
<!-- the *password* key/value credential would be added here automatically -->
			"model": "account.move",
			"action": "action_post",
			"data": [
				{{ $('Merge').first().json.id }}
			]
		]
	},
	"id": {{ Math.floor(Math.random() * 1000000000) }}
}