Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Controller not working

Subscribe

Get notified when there's activity on this post

This question has been flagged
controllers
2 Replies
1899 Views
Avatar
Moses Mwaba

Hey guys please help. I have created a controller in odoo17 and when try to POST a request using postman I am getting the error below.

2025-06-23 08:15:22,702 18051 INFO ? werkzeug: 127.0.0.1 - - [23/Jun/2025 08:15:22] "POST /api/student/create HTTP/1.1" 404 - 1 0.003 0.042



I have also imported my file in the __init__.py

from . import student_api_controller

Here is the url I am using in postman
http://localhost:8069/api/student/create

Here is my controller 

from odoo import http
from odoo.http import request
import json
import urllib
import logging

_logger = logging.getLogger(__name__)


class StudentAPI(http.Controller):

@http.route('/api/student/create', type='http', auth='public', methods=['POST'], csrf=False)
def create_student(self, **kw):
try:
# Manually parse JSON data from the request body
data = json.loads(request.httprequest.data.decode('utf-8'))

# Ensure the data is a list
if not isinstance(data, list):
response = {"success": False, "error": "Data should be a list of students."}
return request.make_response(json.dumps(response), headers={'Content-Type': 'application/json'})

study_mode_mapping = {
'Distance': 'distance',
'Fulltime': 'full_time',
'Parttime': 'part_time'
}

nationality_mapping = {
'Local': 'local',
'SADC': 'sadc',
'International': 'international'
}

responses = []
for student_data in data:
for key in student_data:
if isinstance(student_data[key], str):
student_data[key] = urllib.parse.unquote_plus(student_data[key])

_logger.info("Received data: %s", student_data)

study_mode = student_data.get('study_mode')
if study_mode:
student_data['study_mode'] = study_mode_mapping.get(study_mode, 'distance')

nationality = student_data.get('nationality')
if nationality:
student_data['nationality'] = nationality_mapping.get(nationality, 'local')

required_fields = ['student_id', 'government_id', 'address', 'study_mode', 'email', 'name', 'mobile', 'nationality']
missing_fields = [field for field in required_fields if field not in student_data]
if missing_fields:
responses.append({"success": False, "error": f"Missing fields: {', '.join(missing_fields)}"})
continue

taken_reg = request.env['res.partner'].sudo().search([
('government_id', '=', student_data.get('government_id')),
('is_student', '=', True)
], limit=1)

taken_id = request.env['res.partner'].sudo().search([
('student_id', '=', student_data.get('student_id')),
('is_student', '=', True)
], limit=1)

if taken_id:
responses.append({"success": False, "error": "Another Student with this Student ID already exists!"})
continue

if taken_reg:
responses.append({"success": False, "error": "Another Student with this Government ID already exists!"})
continue

student = request.env['res.partner'].sudo().create({
'is_student': True,
'student_id': student_data.get('student_id'),
'government_id': student_data.get('government_id'),
'street': student_data.get('address'),
'study_mode': student_data.get('study_mode'),
'email': student_data.get('email'),
'name': student_data.get('name'),
'mobile': student_data.get('mobile'),
'nationality': student_data.get('nationality'),
})

responses.append({'success': True, 'student_id': student.id})

return request.make_response(json.dumps(responses), headers={'Content-Type': 'application/json'})

except Exception as e:
_logger.error("Error processing request: %s", str(e))
response = {"success": False, "error": str(e)}
return request.make_response(json.dumps(response), headers={'Content-Type': 'application/json'})
​
0
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

If you're getting a 404 error when trying to POST to a custom route in Odoo 17, make sure your controller is defined correctly. Here's a working example:


from odoo import http

from odoo.http import request

import json


class StudentController(http.Controller):


    @http.route(

        '/api/student/create',

        type='http',

        auth='public',

        csrf=False,

        methods=['POST'],

        cors='*'

    )

    def create_student(self, **kw):

        response = {'message': 'success'}

        return request.make_response(json.dumps(response), status=200)



Also, make sure to add a dbfilter in your odoo.conf file. Without it, the request may not map to the correct database, especially if you're running in a multi-database environment.


Hope it helps

2
Avatar
Discard
Avatar
D Enterprise
Best Answer

Hii,

Please check 
The file is located in your module’s /controllers/ directory.
The controller file is imported in your module's __init__.py like this:

directory like :
your_module/controllers/__init__.py

from . import controllers


Check Route Matching:

@http.route('/api/student/create', type='http', auth='public', methods=['POST'], csrf=False)

Make sure you're using exact match in Postman:

  • URL should be http://localhost:8069/api/student/create (adjust port as needed).
  • Method must be POST.

Testing Route:

@http.route('/api/test', type='http', auth='public', methods=['GET'], csrf=False)

def test_api(self, **kw):

    return "It works!"

 i hope it is use full


0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Controller giving 404 Error
controllers
Avatar
Avatar
Avatar
2
Aug 25
3395
How to add simple logic inside methods of Odoo 16 website controller?
controllers
Avatar
Avatar
Avatar
3
Jun 24
4675
Controller or middleware that handles all the requests
controllers
Avatar
Avatar
1
Mar 23
4825
Controller for auto fill
controllers
Avatar
0
Apr 17
3693
Custom controllers not working
controllers
Avatar
0
Mar 15
4853
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now