Apporving POs using REST

Trying to send Approval for Purchase order through REST suing POApvMsg service
Using the Swagger UI (https://ourserver/ourinstance/api/v1/Erp.BO.POApvMsgSvc/Update) we can post the following int the Update method

{“ds”: {“POApvMsg”: [{“Company”: “SISTNZ”,“PONum”: 111681,“MsgType”: 1,“MsgDate”: “2019-02-12T00:00:00”,“MsgTime”: “34944”,“MsgTo”: 31,“MsgFrom”: 13,“MsgText”: “”,“ApproverResponse”: “APPROVED”,“DcdUserID”: “derekm”,“SysRevID”: “3749847938”,“SysRowID”: “44ccd382-6a3b-4616-a8cb-e7d0d82f0497”,“VendorName”: “OFFICEMAX”,“BuyerName”: “Admin Department”,“BuyerLimit”: “1”,“POAmt”: “2407.5”,“ApvAmt”: “2407.5”,“MsgTimeString”: “09:42:24”,“ApproverName”: “”,“BitFlag”: 0,“MsgToName”: “HR Manager”,“RowMod”: “U”}],“ExtensionTables”: []}}

And we get an Approved PO

However when we post this via a Web page we get a server error
We have tried getting a rerun object from GetRows and modifying the data then pushing this to settings.data for AJAX call, we have JSON.stringified the object and also we have tried building a string from scratch all with the same results.

System.InvalidCastException: Unable to cast object of type ‘System.Object’ to type ‘Newtonsoft.Json.Linq.JObject’.
_ at Epicor.RESTApi.DataSources.IceServiceCaller.GetInputParams(ParameterInfo[] plist, Object inputData) in C:_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.RESTApi\DataSources\IceServiceCaller.cs:line 513_

_ at Epicor.RESTApi.DataSources.IceServiceCaller.CallCustomMethod(TypeMapping typeMapping, ContextInfo context, String methodName, Object inputObject) in C:_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.RESTApi\DataSources\IceServiceCaller.cs:line 260_

_ at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)_

_ at Epicor.RESTApi.Controllers.CustomActionController.CustomMethod(Object input) in C:_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.RESTApi\Controllers\CustomActionController.cs:line 25_

_ at lambda_method(Closure , Object , Object[] )_

_ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)_

_ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)_

_ at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)_

_ at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)_

_ at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)_

_ at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)_

_ at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)_

_ at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()_

— End of stack trace from previous location where exception was thrown —

_ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()_

_ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Any advice on resolving? Have looked around and theres a lot of chatter about using C# components to resolve the issue

Self Diagnosed a resolution.
Its always worth checking that you have got the correct Accept type in the header (we’d been playing with Postman, copied the header across and hadn’t realised the Accept token wasn’t set to application/json).
Hope this helps if others are getting a similar issue

Cheers

1 Like