0

hello here I am a beginner using odoo, where I am still confused about creating an api, I want to create a partner api where I can get and post to be used in react. I have matched the code with gpt but still when the url is called it is still 404. here is my code and folder arrangement

Custom_Api/
├── __init__.py
├── controllers/
│   ├── __init__.py
│   └── main.py
└── models/
    ├── __init__.py
    └── __manifest__.py
#Controlers>Main.py

from odoo import http
from odoo.http import request

class PartnerApi(http.Controller):

    @http.route('/api/partners', type='http', auth='public', methods=['GET'], csrf=False)
    def get_partners(self):
        partners = request.env['res.partner'].sudo().search([])
        result = []
        for partner in partners:
            result.append({
                'id': partner.id,
                'name': partner.name,
                'email': partner.email,
            })
        return result

    @http.route('/api/partner', type='http', auth='public', methods=['POST'], csrf=False)
    def create_partner(self, **kwargs):
        name = kwargs.get('name')
        email = kwargs.get('email')

        if not name:
            return {'error': 'Name is required'}

        partner = request.env['res.partner'].sudo().create({
            'name': name,
            'email': email
        })
        return {
            'success': True,
            'id': partner.id,
        }

when I open http://localhost:8070/api/partners, then 404, when http://localhost:8070 then succes

 {
#Manifest
        'name': 'REST API for Res Partner v2',
        'version': '1.0',
        'depends': ['base'],
        'data': [],
        'installable': True,
        'auto_install': False,
    }
2
  • You have misspelled the filename. You need to rename _manifest_.py to __manifest__.py. ODOO Module Manifests Commented May 20 at 9:49
  • @Julian owh sorry that's just a mistake in writing the question, which is actually already manifest but still not running. Commented May 20 at 9:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.