This JavaScript code sends a POST request to a Python controller but the two values (name and country) are never received:
const apiBtn = document.querySelector('#api_btn');
if (apiBtn) {
apiBtn.addEventListener('click', () => {
fetch('/api/proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ 'name': 'Gerhart', 'country': 'Germany' })
})
.then(res => res.json())
.then(result => {
document.querySelector('#api_output').textContent = result.result.response;
})
.catch(err => console.error('proxy call failed:', err));
});
}
controller:
import requests
from odoo import http
from odoo.http import request
class MyController(http.Controller):
@http.route('/api/proxy', type='json', auth='user', methods=['POST'], csrf=False)
def api_proxy(self, name, country):
resp = requests.post(
'https://apiserver.com/myapi.php',
data={'name': name or '', 'country': country or ''},
timeout=10
)
return resp.json()
The response from the API is received and relayed successfully back to the JavaScript code, but it's missing the two values.
If the two values are hardcoded into the data, the API receives the values and responds with them.
data={'name': 'Gerhart', 'country': 'Germany'}
Does Odoo 19 require some additional protocol?
@Codesphere: Thank you most kindly, for the suggestion and the ultimate solution. That resolved the issue perfectly.
@Kunjan Patel: Thank you, my friend. You're always there for me.
I do have to apologize again for replying like this, as commenting and upvoting are still not enabled for my newbie account.
Thank you for sharing