Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
1013 Visualizzazioni

I am trying to build a custom integration between Salesforce and Odoo 16 Enterprise using a custom module and API key-based authentication.

What I’ve Done:

  • Created a custom module with a @http.route('/sf/get_products', auth='api_key', type='json', methods=['POST'], csrf=False)
  • Created a boolean field sfcost on product categories, used to filter products returned in the response
  • Generated an API key from an Internal User (with Inventory/User access)
  • Set auth_api_key = True in odoo.conf
  • Restarted the Odoo service fully

Problem:

Despite all correct headers and method (Authorization: Bearer <key>, Content-Type: application/json, POST), Odoo always returnsodoo.exceptions.AccessDenied: Access Denied


I even created a test route /sf/ping to just return the user name and still get AccessDenied.


Avatar
Abbandona

Can you elaborate on auth='api_key' since that's not actually a thing

Risposta migliore

hii,

Enable API Key Authentication in odoo.conf

You're correct to set:
auth_api_key = True

Make sure it is not commented out, and Odoo has been restarted after this change.

Use the Correct HTTP Header

For auth='api_key', Odoo expects the header exactly like this:
Authorization: Bearer <API_KEY>

API Key Must Belong to a User with Correct Group Access

You mentioned the user has Inventory / User access. That’s good for product data. But make sure this user also has access to "Technical Features" or is in the group that can access the endpoint logic (e.g., if your route does ORM queries).

Also:

  • Check that the API key was generated for an Internal user, not a portal or public user.
  • Confirm the key is still active and tied to the right user.

This is case-sensitive, and no extra space or typo is tolerated.

Test with a minimal route:
@http.route('/sf/ping', auth='api_key', type='json', methods=['POST'], csrf=False)

def ping(self, **kwargs):

    return {"user": request.env.user.name}

Test with curl:
curl -X POST https://yourdomain.com/sf/ping \

  -H "Authorization: Bearer <your_api_key>" \

  -H "Content-Type: application/json" \

  -d '{}'


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
lug 25
385
1
lug 25
5264
0
lug 25
806
0
giu 25
835
1
giu 25
1000