N8n API - Post /credentials with Oauth2 data schema

Hello,

I currently have an issue by trying to create an Oauth2 API credentials with the n8n API.
After following the correct data schema to create the credential, I receive the following error: "request.body.data does not match allOf schema [subschema 0] with 1 error[s]:,request.body.data is not exactly one from [subschema 0],[subschema 1],[subschema 2]".

For information here is my body request:

{
  "name": "Oauth API test",
  "type": "oAuth2Api",
  "data": {
    "grantType": "authorizationCode",
    "authUrl": "https://url.com/authorize",
    "accessTokenUrl": "https://url.com/oauth/token",
    "clientId": "123456",
    "clientSecret": "12345secret",
    "scope": "offline_access right:write:admin",
    "authQueryParameters": "",
    "authentication":"header"
}
}

I use the desktop app, and the API playground to make this call.

Do you have any idea how to solve this issue?

Thanks a lot,
Jordan

Hi @jsasportas, welcome to the community!

I am sorry to hear you’re having trouble, unfortunately I am not sure I fully understand the problem. Can you confirm to which service exactly you are trying to connect and perhaps share a screenshot of the error message (to understand its context)?

Hi @MutedJam , thanks, glad to find out about your great product!

For a bit more context, we are trying to create an Oauth2 connection with the endpoint POST /connections.
The goal is that each client has a different connection, so for each new client using our workflow we will create a new connection with this API endpoint (and then following one of these guides Programatically passing credentials into a Workflow).

For more context, here is the curl:

curl --location --request POST 'http://host:port/api/v1/credentials' \
--header 'X-N8N-API-KEY: api_key_n8n' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "Oauth API test",
  "type": "oAuth2Api",
  "data": {
    "grantType": "authorizationCode",
    "authUrl": "https://url.com/authorize",
    "accessTokenUrl": "https://url.com/oauth/token",
    "clientId": "12345",
    "clientSecret": "12345abcd",
    "scope": "offline_access scope:write:admin",
    "authQueryParameters": "",
    "authentication":"header"
}
}'

And the response:
"message": "request.body.data does not match allOf schema [subschema 0] with 1 error[s]:,request.body.data is not exactly one from [subschema 0],[subschema 1],[subschema 2]"

Hope this makes it clear.

Thanks,
Jordan

Thanks so much for clarifying! Have you checked the response to the GET /api/v1/credentials/schema/oAuth2Api request? In theory, this should contain the required schema for your request.

That said, I haven’t tried out this endpoint first hand yet, but have booked some time to take a closer look tomorrow. I’ll report back when I had a chance to test this.

Hey @MutedJam , yes I actually followed the schema of GET /api/v1/credentials/schema/oAuth2Api, here is the results of this endpoint:

{
    "additionalProperties": false,
    "type": "object",
    "properties": {
        "grantType": {
            "type": "string",
            "enum": [
                "authorizationCode",
                "clientCredentials"
            ]
        },
        "authUrl": {
            "type": "string"
        },
        "accessTokenUrl": {
            "type": "string"
        },
        "clientId": {
            "type": "string"
        },
        "clientSecret": {
            "type": "string"
        },
        "scope": {
            "type": "string"
        },
        "authQueryParameters": {
            "type": "string"
        },
        "authentication": {
            "type": "string",
            "enum": [
                "body",
                "header"
            ]
        }
    },
    "allOf": [
        {
            "if": {
                "properties": {
                    "grantType": {
                        "enum": [
                            "authorizationCode"
                        ]
                    }
                }
            },
            "then": {
                "oneOf": [
                    {
                        "required": [
                            "authUrl"
                        ]
                    },
                    {
                        "required": [
                            "authQueryParameters"
                        ]
                    },
                    {
                        "required": [
                            "authentication"
                        ]
                    }
                ]
            },
            "else": {
                "allOf": [
                    {
                        "not": {
                            "required": [
                                "authUrl"
                            ]
                        }
                    },
                    {
                        "not": {
                            "required": [
                                "authQueryParameters"
                            ]
                        }
                    },
                    {
                        "not": {
                            "required": [
                                "authentication"
                            ]
                        }
                    }
                ]
            }
        }
    ],
    "required": [
        "grantType",
        "accessTokenUrl",
        "clientId",
        "clientSecret",
        "scope"
    ]
}

I feel like the schema conditions was respected with my request.

Thanks again for the help,
Jordan

Thanks so much @jsasportas. Unfortunately, even after playing around with this for quite a while now I can’t figure out what might be missing here. @RicardoE105 do you have any idea what might be wrong with the above request creating OAuth2 credentials via the REST API?

Got fixed. We will let you know when it’s released.

1 Like

Great, thanks @RicardoE105

1 Like

Got released with [email protected]