daryl
Janvier 10, 2021, 3:36
21
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)
siddique
(Siddique Ahmad)
Janvier 10, 2021, 4:19
23
share your model permission etc
1 « J'aime »
daryl
Janvier 16, 2021, 11:02
24
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 »
daryl
Janvier 18, 2021, 3:43
26
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.
Hello
Yes the issue with axios version can be a possibility.
However according their doc, to create a record you have to use PUT, to update a record POST.
Jeanguy
(Petit)
Janvier 18, 2021, 5:37
28
Hello,
Do you know how to create a Sale Order with a PUT request?
I don’t know how to add item is the Sale Order Line List.
Hello @Jeanguy
You need to follow this guide.
https://docs.axelor.com/adk/5.2/dev-guide/web-services/rest.html
So use your SaleOrder object and use the correct endpoint.
Jeanguy
(Petit)
Janvier 19, 2021, 7:58
30
Hi @fabiobottan
Thank you for your response, this is what I did.
I can create a lead for example.
But to create a SaleOrder I have an error, I think it is becoming from the SaleOrderLineList.
Please find below the data I put into body.
{
"data": {
"company":"XXX",
"clientPartner":"T0010 - Client test",
"saleOrderLineList":{
"product": "[123.456] Produit test",
"productName": "Test api",
"price":"19.99",
"attrs":"{\"Test\": \"test\"}",
"unit":"Unité",
"qty":"66"
}
}
}
Hello!
What kind of error do you get?
Jeanguy
(Petit)
Janvier 19, 2021, 10:25
32
this is the trace:
{
« status »: -1,
« data »: {
« string »: « java.lang.IllegalArgumentException: java.lang.ClassCastException@789457c9 »,
« stacktrace »: « java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: java.lang.ClassCastException@789457c9\n\tat com.axelor.db.mapper.Mapper.set(Mapper.java:374)\n\tat com.axelor.db.JPA._edit(JPA.java:411)\n\tat com.axelor.db.JPA.edit(JPA.java:292)\n\tat com.axelor.rpc.Resource.save(Resource.java:951)\n\tat com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:56)\n\tat com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:64)\n\tat com.axelor.web.service.RestService.save(RestService.java:166)\n\tat com.axelor.rpc.RequestFilter.invoke(RequestFilter.java:55)\n\tat com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:56)\n\tat com.axelor.web.service.RestService.create(RestService.java:171)\n\tat com.axelor.rpc.RequestFilter.invoke(RequestFilter.java:55)\n\tat com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:65)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:294)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:248)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:235)\n\tat org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:398)\n\tat org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:205)\n\tat org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)\n\tat org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)\n\tat org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:89)\n\tat com.axelor.db.tenants.AbstractTenantFilter.doFilter(AbstractTenantFilter.java:67)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:44)\n\tat org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)\n\tat org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)\n\tat com.axelor.auth.AuthFilter.doFilterInternal(AuthFilter.java:121)\n\tat org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\tat org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:41)\n\tat org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)\n\tat org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)\n\tat org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)\n\tat org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)\n\tat org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)\n\tat org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)\n\tat org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.axelor.app.internal.AppFilter.doFilter(AppFilter.java:93)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:94)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.axelor.db.tenants.AbstractTenantFilter.doFilter(AbstractTenantFilter.java:67)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.axelor.web.servlet.CorsFilter.doFilter(CorsFilter.java:132)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:121)\n\tat com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:133)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n\tat java.lang.Thread.run(Thread.java:748)\nCaused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@789457c9\n\tat sun.reflect.GeneratedMethodAccessor714.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat com.axelor.db.mapper.Mapper.set(Mapper.java:372)\n\t… 76 more\n »,
« cause »: « java.lang.IllegalArgumentException: java.lang.ClassCastException@789457c9\n\tat sun.reflect.GeneratedMethodAccessor714.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat com.axelor.db.mapper.Mapper.set(Mapper.java:372)\n\tat com.axelor.db.JPA._edit(JPA.java:411)\n\tat com.axelor.db.JPA.edit(JPA.java:292)\n\tat com.axelor.rpc.Resource.save(Resource.java:951)\n\tat com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:56)\n\tat com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:64)\n\tat com.axelor.web.service.RestService.save(RestService.java:166)\n\tat com.axelor.rpc.RequestFilter.invoke(RequestFilter.java:55)\n\tat com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:56)\n\tat com.axelor.web.service.RestService.create(RestService.java:171)\n\tat com.axelor.rpc.RequestFilter.invoke(RequestFilter.java:55)\n\tat com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:65)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:294)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:248)\n\tat org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:235)\n\tat org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:398)\n\tat org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:205)\n\tat org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)\n\tat org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)\n\tat org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:89)\n\tat com.axelor.db.tenants.AbstractTenantFilter.doFilter(AbstractTenantFilter.java:67)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:44)\n\tat org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)\n\tat org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)\n\tat com.axelor.auth.AuthFilter.doFilterInternal(AuthFilter.java:121)\n\tat org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\tat org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:41)\n\tat org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)\n\tat org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)\n\tat org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)\n\tat org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)\n\tat org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)\n\tat org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)\n\tat org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.axelor.app.internal.AppFilter.doFilter(AppFilter.java:93)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:94)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.axelor.db.tenants.AbstractTenantFilter.doFilter(AbstractTenantFilter.java:67)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.axelor.web.servlet.CorsFilter.doFilter(CorsFilter.java:132)\n\tat com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)\n\tat com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:121)\n\tat com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:133)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n\tat java.lang.Thread.run(Thread.java:748)\n »,
« message »: « java.lang.ClassCastException@789457c9 »,
« class »: « java.lang.IllegalArgumentException »
}
}
siddique
(Siddique Ahmad)
Janvier 19, 2021, 10:40
33
my suggestion is to not consume API in this way rather call new method where you have all data received via json it’s default
than you can easily create and sale order or whatever you need
and call services method and enjoy axelor integration
1 « J'aime »
I agree!
@Jeanguy It’s easier in the way described by @siddique
The class cast exception seems you are sending a payload not properly with the format of SaleOrder
Jeanguy
(Petit)
Janvier 19, 2021, 12:56
35
Thank you.
Do you have a documentation about this way?
siddique
(Siddique Ahmad)
Janvier 19, 2021, 1:31
36
it’s same rest service
create method in controller
create action linked to controller
call rest service of action end point
it will have data as json and no model required
json will be key value pairs
Jeanguy
(Petit)
Janvier 19, 2021, 1:50
37
Do you know if there are any examples because I don’t know this way at all, I’m more comfortable with API calls with json.
siddique
(Siddique Ahmad)
Janvier 19, 2021, 2:29
38
Jeanguy
(Petit)
Janvier 19, 2021, 5:18
39
I know how to create an action, but I don’t know how to put data and how to call it from webservice.
siddique
(Siddique Ahmad)
Janvier 19, 2021, 6:13
40
I shared links they are not helping?