1
const handleSubmit = async (e) => {
        e.preventDefault();
        const response = await axios.post(
            "http://localhost/web/session/authenticate",
            {
                jsonrpc: "2.0",
                method: "call",
                id: 1,
                params: {
                    login: `${login.email}`,
                    password: `${login.password}`,
                    db: "odoo",
                    context: {},
                },
            },
            {
                headers: {
                    "Content-Type": "application/json",
                },
            },
            { withCredentials: true }
        );

        console.log("response", response);
    };

I am using React, and trying to call Odoo-15 APIs. This is how I successfully call authenticate on my local Odoo-15 and it automatically sets the session-id in cookies.

const getTasks = async () => {
        const response = await axios.post("http://localhost/web/dataset/search_read", {
            headers: {
                "Content-Type": "application/json",
            },
            credentials: "include",
            body: JSON.stringify({
                jsonrpc: "2.0",
                method: "call",
                id: 1,
                params: {
                    model: "res.users",
                    fields: ["id", "user_id", "name", "state"],
                    domain: [],
                    offset: 0,
                    limit: 0,
                    sort: "id ASC",
                    context: {
                        lang: "en_US",
                        tz: "Europe/Brussels",
                        uid: 1,
                    },
                },
            }),
        })

Now, I tried to get the some records but it gave this error

to load resource: the server responded with a status of 404 ()

Rock Lee
  • 11
  • 2

1 Answers1

0

You are using the wrong endpoint. you should be using "$url/xmlrpc/2/common" and "$url/xmlrpc/2/object" only.

To make your life easier, use JSON-RPC-client. Example:
https://www.npmjs.com/package/react-jsonrpc-client

To get more examples of how to use Odoo external API read:
https://www.odoo.com/documentation/master/developer/reference/external_api.html

Paxmees
  • 1,540
  • 1
  • 15
  • 28