0

I have a process that uses the REST API to create two bills for a project task. The first bill for a vendor of a particular vendor class always gets created successfully and can be processed normally. The second bill for a vendor of a different vendor class almost always fails, throwing a 500 Internal Server error. They both pass the same data structure to the same function to create the bill and I've compared the JSON that is being marshaled from the structures and passed to the API. It is identical in structure--just the values are different. Here's the body of the response when I get the error:

{
    "message": "An error has occurred.",
    "exceptionMessage": "Object reference not set to an instance of an object.",
    "exceptionType": "System.NullReferenceException",
    "stackTrace": "   at PX.Api.ContractBased.SystemContracts.V2.RestController.PutEntity(EntityImpl entity, String select, String filter, String expand, String custom)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"
}

I am logging the JSON that I'm passing to the API call. The strange thing is if I send the same JSON via Postman, it works.

Here's the JSON I'm passing.

{
    "note": "Bill for Job Assignment",
    "Amount": {
        "value": 210
    },
    "Date": {
        "value": "2020-12-28"
    },
    "DueDate": {
        "value": "2021-01-27"
    },
    "Hold": {
        "value": "false"
    },
    "LocationID": {
        "value": "MAIN"
    },
    "Terms": {
        "value": "SCHEDULE"
    },
    "Type": {
        "value": "Bill"
    },
    "Vendor": {
        "value": "V003700"
    },
    "VendorRef": {
        "value": "FC02000029"
    },
    "Details": [
        {
            "Branch": {
                "value": "EDS"
            },
            "InventoryId": {
                "value": "FEEFORSERVICE"
            },
            "Project": {
                "value": "V000026C000166"
            },
            "ProjectTask": {
                "value": "020000961900029"
            },
            "Qty": {
                "value": 6
            },
            "UnitCost": {
                "value": 35
            }
        }
    ],
    "custom": {
        "Document": {
            "AttributeDETAILLOC": {
                "type": "CustomStringField",
                "value": "1240 Jones Mill Rd"
            },
            "AttributeENDTIME": {
                "type": "CustomStringField",
                "value": "00:00"
            },
            "AttributeJOBDATE": {
                "type": "CustomDateTimeField",
                "value": "12/27/2020"
            },
            "AttributeJOBNBR": {
                "type": "CustomStringField",
                "value": 9619
            },
            "AttributeOFIDNBR": {
                "type": "CustomStringField",
                "value": "937"
            },
            "AttributeOFCREMPNBR": {
                "type": "CustomStringField",
                "value": "280"
            },
            "AttributeVENDORID": {
                "type": "CustomStringField",
                "value": "V003700"
            },
            "AttributeEMPNAME": {
                "type": "CustomStringField",
                "value": "Jones, James Earl"
            },
            "AttributeSTARTTIME": {
                "type": "CustomStringField",
                "value": "18:00"
            }
        }
    }
}

I'm hoping that there are clues in the stack trace that mean something to somebody more experienced with the Acumatica REST API than I am.

  • Is it possible that the 2 vendor classes have a different set of Attributes needed? and one of those is required? Hence the null reference? Just a thought. – Diane Cawley Dec 29 '20 at 02:59

1 Answers1

0

I was able to solve the problem. It turns out the issue was related to some (secret) change in status of the Project Task associated with the bills I was creating. Once I had released one bill, I was unable to create or release another bill. I added a step in between to change the status of the Project Task to "Active" (which it had been before adding the first bill) before releasing the second bill, and it worked.

Yet another undocumented requirement using the REST API. There's an awful lot of guesswork involved, but once you get it all figured out, it works great!