Rest API Post Request

might be some technical issues but from post I see constant name not matching

can you please confirm that

Exactly, postman is ok but not the browser.

I haven’t tested with curl as I am not familiar with the technology however I will give it a try and report back to you. I’m using Chrome so I will also try in another browser today in case the results vary. Thanks for the suggestion.

Hi Siddique,

Thats a good spot but unfortunately that is just an error on my behalf when making the post here on the forum. I have updated the post.

Thanks Siddique.

where you are intercepting requests to attach the cookie ?

I am using the line above to handle cookie attachment (if this is what you meant in your question). As seen in the original post the JSESSIONID and CSRF-TOKEN are being sent in the request in the headers so to the best of my knowledge I can only assume this isn’t the issue.

#!/bin/bash
curl -c cookies.txt --location --request POST 'https://localhost:8080/login.jsp' --header 'Content-Type: application/json' --data-raw '{
    "username": "admin",
    "password": "admin"
}'
curl -b cookies.txt --location --request POST 'https://localhost:8080/ws/action' --header 'Content-Type: application/json' --data-raw '{"model":"com.axelor.meta.db.MetaView","action":"action-meta-restore-all","data":{"_domain":null,"_domainContext":{"_id":null,"_model":"com.axelor.meta.db.MetaView"},"operator":"and","criteria":[],"_signal":"restoreAll"}}'

above work painless, you are fetching cookies from login url, right ? and saving in local storage?

Yes I am fetching the cookies when I login using the same URL as you have included above:
https://localhost:8080/login.jsp

These cookies are being automatically handled by axios when using the:

axios.defaults.withCredentials = true;

I have attached the screenshot below to show the cookies are saved:

I have compared the JSESSION and CSRF token ID’s here to the ID’s for these fields being sent in the POST request and they are the same.

is there a way to inspect it, like we do developer tools ? i feel something getting lost in the flight ?
what logs you seeing in console ?

I have attached as much information as I can get using the Chrome developer tools. Thank you a thousand for helping me with this issue.

Screenshot 2021-01-10 at 14.47.44

CORS allowed ??

are you able to fetch any other model data ??

Yes CORS is allowed. The issue is strange because I can successfully make GET, DELETE and PUT requests. The only issue is with POST.

I can fetch model data.
I can delete models.
I can create data.
I cannot edit date ie POST request.

Hello @daryl
Double check.
In your 1st post you tested to push at com.axelor.ross.db.ItemMenu/… (in your postman test it works)
In the screenshot attached you are testing
com.axelor.ross.db.ItemMenu/105

Basically it’s a different endpoint maybe with different permissions.

Hi Fabio,

Apologies in the original post I was meant to write:
com.axelor.ross.db.Item

I have updated the original. Thank you for pointing this out though.
I have made sure the endpoints are correct. Unfortunately both postman and the browser are hitting the same endpoint, I kinda wish this was the problem though haah! Thanks again.

Hi @daryl
Ok no problem.
Test directly with curl (try with @siddique post ). I think it’s an issue with your browser (the plugin or whatever your’re using to set the header)

share your model permission etc

1 « J'aime »

So I found the the solution. I don’t know if this is expected behaviour because it is not what the documentation says to do in order to update a record via the api.

I am able to update an existing record by making a PUT request with a records id, version and any other necessary fields in the body of the request.

I also removed the id from the request URL.

For example:


Hopefully this is of some use to any other frustrated developers.

Thank you for all the help and advice - its much appreciated. @siddique @fabiobottan

2 « J'aime »

Hello @daryl
Before were you using POST (axios.post).
The API endpoint is designed to accept only PUT calls, that was the reason why you got 403.
I’m just guessing, I think you can find this at your RestController « @PUT »

Hey Fabio,

Hmm I might not be understanding correct however the Axelor documentation shows POST requests should be available.

https://docs.axelor.com/adk/5.2/dev-guide/web-services/rest.html

Possibly its a browser related issue or the version of Axios that I am using is old - I’m not so sure. But at least there is a work around solution for now.

Thanks again.