Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
850 Vistas

Hello,

I'm developing an app which requires getting PDF of invoices from External API.


I'm able to generate a download link using account.move.action_invoice_download_pdf method, but it only works with a logged user within a web browser, if i get this url via postman, I receive the login page html.


I tried to add the bearer token in the Authorization header, it doesn't work.


So I'd like to know if there is a method which allows to directly download a report/pdf via API.

I tried acount.move.action_print_pdf, I receive 

{

"jsonrpc": "2.0",

"id": null,

"result": {

"context": {

"active_ids": [

161

]

},

"data": null,

"type": "ir.actions.report",

"report_name": "account.report_invoice_with_payments",

"report_type": "qweb-pdf",

"report_file": "account.report_invoice_with_payments",

"name": "Facture PDF"

}

}


then I try ir.actions.report.report_action like this: 


{

  "jsonrpc": "2.0",

  "method": "call",

  "params": {

    "service": "object",

    "method": "execute",

    "args": [

      "{{ _.db_name }}",

      2,

      "{{ _.api_key }}",

      "ir.actions.report",

      "report_action",

[161]

,  { "model": "account.move" },

"account.report_invoice_with_payments"

    ]

  }

}



But I receive the error message: "cannot access local variable 'active_ids' where it is not associated with a value"

There is not documentation explaining how to do that, I'm reading the GitHub but still didn't find any solution...


Avatar
Descartar

Bonjour,

 

Merci pour votre message.

 

Je suis actuellement absent et prendrai connaissance de votre mail à mon retour, le 8 mai 2025.

 

En cas d’urgence, vous pouvez contacter le support :

<![if !supportLists]>·<![endif]>par téléphone au 071/36.60.62

<![if !supportLists]>·<![endif]>par mail à l'adresse suivante : support@mhc.be

 

Merci de votre compréhension.

 

Bien à vous.

 

Julien Durieux - MHCONSULTANTS

 

Mejor respuesta

That's expected behavior.

The endpoint is designed to work within a logged-in web session. If you're accessing it via Postman or another external client, you first need to authenticate.

By default, Odoo uses session-based authentication, which means it expects a valid user session (i.e., cookie-based, from a browser login). Simply providing a bearer token won't work unless you’ve implemented a proper token-based authentication mechanism.

If you want to call this API from an external system, here are a few approaches:

  1. Use session authentication: First log in to Odoo using a POST request to /web/session/authenticate, get the session ID from the response, and use that in subsequent requests via the Cookie header.
  2. Implement token-based access: You can expose your own controller (using @http.route) and implement token-based authentication logic, or use a module like Restful API (by OCA) that supports token-based auth.
Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 25
1125
3
mar 25
2054
2
feb 25
4936
1
feb 25
1835
1
may 25
1261