Skip to Content
Menu
This question has been flagged
1 Reply
1715 Views

I have created custom API module for odoo 18. My endpoint REST APIs are working fine in local version. But when I try to use it in the hosted version it gives 404 error.




Avatar
Discard
Best Answer

When your custom API module works in your local Odoo instance but gives a 404 error on the hosted version, it indicates that the hosted environment may not be configured to load your custom module or that there are deployment-specific issues. Here are steps to diagnose and resolve this issue:

1. Verify Module Installation on Hosted Version

Ensure your custom API module is installed and available on the hosted instance:

  • Check Installed Modules:
    • Go to Apps and ensure your module is listed as installed.
  • Install/Upgrade Your Module:
    • If not installed, install it via the Apps menu or run:
      bashCopy codepython3 odoo-bin -u <your_module_name> -c /etc/odoo/odoo.conf
      

2. Check the API Endpoint Configuration

  • Verify Endpoint Routing: Ensure your custom endpoints are defined correctly in your controllers file and are accessible in the hosted environment.
    Example:
    pythonCopy codefrom odoo import http
    
    class MyAPIController(http.Controller):
        @http.route('/my_api/endpoint', type='json', auth='public', methods=['POST'], csrf=False)
        def my_api_method(self, **kwargs):
            return {'message': 'API is working!'}
    
  • Test Endpoint in Hosted Version: Use a tool like curl or Postman to test the endpoint directly:
    bashCopy codecurl -X POST https://your-hosted-instance.com/my_api/endpoint -d '{}'
    

3. Verify Server Logs

  • Check Logs for Clues: Look for errors in the Odoo log file (/var/log/odoo/odoo.log or equivalent) when the 404 error occurs.
    Key things to look for:
    • Errors related to module loading.
    • Missing or unregistered routes.
    You can filter logs for your module:
    bashCopy codegrep '<your_module_name>' /var/log/odoo/odoo.log
    

4. Inspect Hosted Environment Configuration

  • Custom Module Deployment: Ensure the custom module is properly uploaded to the hosted instance. Verify:
    • The module is in the addons directory or an equivalent path.
    • The path to your custom module is listed in the addons_path of the Odoo configuration file.
    Example of a valid addons_path:
    iniCopy codeaddons_path = /usr/lib/python3/dist-packages/odoo/addons,/opt/odoo/custom_addons
    
  • Restart Odoo Server: If you recently added or updated the module, ensure the server is restarted:
    bashCopy codesudo service odoo restart
    

5. Verify Access Control and Authentication

  • Authentication Requirements: If your API requires authentication, ensure the credentials used in the hosted version are correct.
    • If using auth='public', ensure the endpoint doesn't have unnecessary restrictions.
    • For authenticated endpoints, verify the Authorization header is included in requests.
  • Cross-Origin Resource Sharing (CORS): If accessing the API from a different domain, ensure the hosted instance has proper CORS settings.

6. Firewall or Proxy Issues

  • Firewall Rules: Ensure that the hosted environment allows traffic on the required port (usually 8069 for Odoo).
  • Reverse Proxy Configuration: If using a reverse proxy (e.g., Nginx), ensure it forwards requests to your custom API correctly. Update the proxy configuration if necessary.
    Example Nginx configuration for API:
    nginxCopy codelocation /my_api/ {
        proxy_pass http://127.0.0.1:8069/my_api/;
    }
    

7. Debugging in Hosted Environment

  • Enable Debug Mode: Temporarily enable debug mode to inspect if your module routes are loaded:
    bashCopy codepython3 odoo-bin -c /etc/odoo/odoo.conf --dev=all
    
  • Test All Routes: Use Odoo's route debugging to check if your custom route is registered:
    • Access /web/environment/routes to see all loaded routes.

8. Redeploy the Module

If the issue persists, re-upload and reinstall your module:

  • Remove the existing module from the addons path.
  • Re-upload the module folder to the appropriate addons_path.
  • Restart the Odoo server and reinstall the module.

9. Host Provider Limitations

If your Odoo instance is on a hosted SaaS platform (e.g., Odoo Online), it may restrict custom module usage or require specific deployment steps. Contact your hosting provider to confirm:

  • If custom modules are supported.
  • The process to deploy custom modules in their environment.

Summary Checklist

  1. Ensure your module is installed and accessible in the hosted instance.
  2. Verify the API endpoint configuration in your module.
  3. Check server logs for routing or deployment errors.
  4. Confirm the module is in the addons_path.
  5. Restart the Odoo server after module changes.
  6. Ensure the hosted instance allows traffic to your API endpoint.
  7. Confirm with the hosting provider for any restrictions on custom modules.

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 25
938
1
Aug 25
320
2
Jul 25
2775
3
Jul 25
579
4
Jul 25
348