Skip to main content

I have a webhook working in Acumatica. I want to be able to return, to the caller, some JSon of the transaction that they created instead of just status 200.

public async Task<System.Web.Http.IHttpActionResult> ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
try
{
//do some things
}
catch (Exception ex)
{
var failed = new ExceptionResult(ex, true, new DefaultContentNegotiator(), request, new[] { new JsonMediaTypeFormatter() });
return failed;
}

//This is where I’m stuck. I’d be happy to return some JSon, similar to what the API would return after a successful call

return ???
}

Intellisense is good at telling me what I can’t do, not really good at telling what I should do. :)

I your webhook is already working then you can use the Ok class to send a 200 response with some content, like this:

return new Ok(new { 
OrderType = new { value = "EO" },
OrderNbr = new { value = "001979" },
...etc...
});

The JSON returned by the API is easy to reproduce if you are familiar with the entity you wish to send, but if it’s not required you can simplify the response because the REST API uses nested objects for each value as illustrated in the code above.

I posted a webhook example in github which you can find here: https://github.com/markoan/acumatica-webhook-example/blob/master/WebhookDemo/WebhookExample.cs

It returns just an empty 200 response, but you can easily modify it to return an object.
 


Thank you Marco, both for your response and for the example in github - that’s what I used to create my webhook.

I think I’m hitting a C# challenge because I’m not seeing how to create the Ok object. It is part of the MVC Core - should I pull that into my project?


My bad, I linked the newest version of the class but in my code I actually used a different library.

My example, and I suppose your code, uses the System.Web.Http library. That version exposes the JsonResult class. You can use it like this:

// If you don't see that class, try adding: using System.Web.Http.Results;
// to the top of your file.

return new Json(new {
OrderType = new { value = "EO" },
OrderNbr = new { value = "001979" },
...etc...
});

 

Sorry for the confusion. Acumatica is migrating to Core so this will still be useful in the future.


Reply