Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
299 Tampilan

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
Buang

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

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jun 25
341
1
Mei 25
859
0
Mar 25
511
1
Des 24
3150
2
Nov 24
1303