Skip to main content

By default, Json responses of a web Service end points looks bellow.

{
"id": "9c089d8c-086c-ee11-8358-06c5a29671a4",
"rowNumber": 1,
"note": {
"value": ""
},
"BaseCurrencyID": {
"value": "USD"
},
"Branch": {
"value": "GRITIRES"
},
"ControlTotal": {
"value": 14800.0000
},
"CurrencyEffectiveDate": {
"value": "2023-03-15T00:00:00+00:00"
},
"CurrencyID": {
"value": "USD"
},

I need to format it as below
 

{
"id": "9c089d8c-086c-ee11-8358-06c5a29671a4",

"rowNumber": 1,

"note": "",
"BaseCurrencyID": "USD",

"Branch":"GRITIRES",

"ControlTotal": 14800.0000,

"CurrencyEffectiveDate": "2023-03-15T00:00:00+00:00"
}

and i need to customize the request body format also as above. is it possible in Acumatica ERP?

Hi @PDharmasena10,


In Acumatica ERP, the default format of the JSON responses and request bodies from web service endpoints follows a standard structure, where each field is an object with a "value" property. However, I believe  the customization of these JSON structures, especially to change them to a simpler key-value format, is not directly supported out-of-the-box within Acumatica's web service API framework.


Hi @PDharmasena10 

No, you can’t change the format (without significant intrusion into the core Acumatica functionality).

That’s the format Acumatica works with. It expects the same body in the request as it sends in a response.

If you’re interacting with the Acumatica through code, you can configure a Serializer-Deserializer that will be able to convert your data from one way to another.

But it depends on your use case.


@Dipak Nilkanth , @andriitkachenko Hi all, Thanks for your comments, Is it possible to sends a http request using HttpClient in .NET through a Graph extension or any other way using a customization? I tried to do that, but still unable to be success. following is just a sample code which I tried.

 #region Actions
public PXAction<RDCripto> LoadCurrentValue;
/PXProcessButton]
/PXUIField(DisplayName = "Load Current Value", Enabled = true)]
protected virtual IEnumerable loadCurrentValue(PXAdapter adapter)
{

// Acuminator disable once PX1008 LongOperationDelegateSynchronousExecution oJustification]
PXLongOperation.StartOperation(this, delegate ()
{

fetchData();

});

return adapter.Get();
}

public void fetchData()
{

using (var ts = new PXTransactionScope())
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.coincap.io/v2/assets");
var response = await _client.SendAsync(request);
response.EnsureSuccessStatusCode();

ts.Complete();

}

}

 


Try something like this

 

public async Task<string> FetchData()
{
  
    using (var client = new HttpClient())
    {
            var result = await client.GetAsync("https://api.coincap.io/v2/assets");
            if (result.IsSuccessStatusCode)
            {
                return await result.Content.ReadAsStringAsync();
            }
            else
            {
                return result.ToString();
            }
    }

}


@PDharmasena10 

Your code looks mostly good for me:

Here I’ve placed your code on one of my screens and you can see I got the response (2 windows to the right).

If it doesn’t work for you - might be something related to how you create your client.

Here’s your code with my changes:

            Task.Run(async () =>
{
using (var ts = new PXTransactionScope())
using (var client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.coincap.io/v2/assets");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

ts.Complete();

}
});

to tinker with.

Your code lacks the part where you read the response and show it on the screen - if you didn’t debug the button, but clicked on it on the UI and expected to see the result there, that might be the reason. All that you’ll get on the UI with this button is “The operation has completed.” toast message in the top right corner.


Hi, @Patrick Chen , @andriitkachenko I fixed the code, now it is working. What about the reliability of this approach compered to web service endpoints? I’m going to use this method to integrate a 3rd party system with Acumatica.

 


Not sure what you mean by the “reliability of the approach”.
If you use a web service endpoint, you need to create a mediator service to integrate your 3rd party system (customization, plug-in, separate service, you name it) that will interact with Acumatica through API.

If you use customization, you need to develop an application that will interact with your 3rd party system.

It’s basically the same thing, just with different directions. Both approaches are sound, the rest depends on your implementation.


@andriitkachenko Okay, I understood, Thanks for your support.

 


Reply