Accessing REST api through node.js

So I have been tinkering around trying to learn node.js and understand more about the REST api. Yesterday I was able to successfully use the GET method to pull some data out with a node.js application.

However a few questions came to mind, and I was hoping someone here could shed some light on them.

  1. When working with the REST api why create a query to a specific service rather than making a BAQ to pull data from?

  2. Once you get the data from the REST api. What is the best way to use the JSON? Do I just put it directly into an array, and use it from there? or is there a different method I should be using.

I am not familiar with node.js so I cannot answer your second question well, but just in general

If you don’t want to/can’t have BAQs developed for your integration, the BO services are completely appropriate. There is no real advantage in my mind to going direct service route for data pulling, other than that you don’t need to have knowledge of BAQs and table relations. There are also some advantages present if utilizing the services to invoke updates via the business object directly, which would be more challenging with a BAQ as you’d need to develop and maintain a uBAQ to do so. If you are on a high enough version, Functions are my preferred way of integration via the API. Functions allow you to define the request and response schema as well as orchestrate any business logic (i.e. create a sales order) inside of the function. The direct service call design are very chatty and have heavy, complex datasets. This can be minimized via BAQ service calls, but just trying to explain some of the differences.

In my limited knowledge of your second question, I have seen it done in PHP by storing the data in an array and interacting with it from there. Perhaps they are similar? In .NET, I interact with my returned JSON via the use of dynamic objects or I would utilize DTOs if the design was rigid enough.

1 Like

To add onto Aaron’s answer a bit…
-You can use the built in JSON JavaScript functions, there are also node JSON packages available that can do more.
-If you are updating data sometimes a series of service calls are required to maintain data integrity and, yea, wrap them all up in an Epicor function if they are available to you.