Reputation: 557
I am tasked with replacing a manual procedure in Acumatica with an automated one using the REST API. I have been through the integration guide, but I do not know how to determine the endpoints that match up with the manual process I am replacing. This is so basic, but I cannot find the answer anywhere in the documentation I've read through.
Here is the manual process:
(There are two sides to the process, an Import Synchronization and an Export Synchronization -- but I will just focus on the Export for now.)
1) Go into "Export Scenario" option under integration, and choose the "Available Inventory" Scenario -- then select "Prepare and Export." 2) Go to Data Providers and choose "AvailableInventory" Provider. Then select Export from Synchronization tab.
The end result of this is a CSV file that I take to the POS system and import it there.
So, from the API perspective, I need to go to the Inventory via an endpoint, and select all inventory based on date criterion, and then write that out to a CSV file.
But how do I know what endpoint to use, and how can I ensure I am gathering all of the data in my C# code that we were getting using the data provider and data scenario in the manual process?
I've looked in the documentation, but I don't seem to be able to find this.
Upvotes: 2
Views: 721
Reputation: 7706
First, you need to create an Endpoint for the Export By Scenario page.
Go to Web Service Endpoints (SM207060) page and extend any existing endpoint.
Add a new Endpoint and map it to the Export By Scenario page.
Add the Name and Status of the Scenario as a parameter.
Prepare and Export is starting long operation, in order to get the correct file you will need to do a get request and check if the Status is completed.
Add action under endpoint and map it to prepareExport action of the graph.
Add the Name of the scenario as a parameter of the Action.
Now is time for the action. Below is example code how to invoke the our action on the “Export AP Vendors” export scenario.
var client = new RestClient("http://localhost/ACU19200/entity/DefaultExt/18.200.001/ExportByScenarios/prepareExport");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n\t\"entity\":{\n\t\t\"Name\" : {\"value\":\"Export AP Vendors\"}\n\t},\n\t\"parameters\":{\n\t\t\n\t}\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
As a result, you will get 202 Response Code if everything has been handled correctly.
Now we need to check if the scenario has worked and the file is export.
var client = new RestClient("http://localhost/ACU19200/entity/DefaultExt/18.200.001/ExportByScenarios/Export AP Vendors");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
As a response to this request you will get the Record of the Scenario, something like below:
{
"id": "730d3b2c-d87f-e411-beca-00b56d0561c2",
"rowNumber": 1,
"note": "",
"Name": {
"value": "Export AP Vendors"
},
"Status": {
"value": "Processed"
},
"custom": {},
"files": [
{
"id": "9479c468-1cfa-4fb5-b8bd-30c10535e525",
"filename": "Data Providers (Export AP Vendors)\\AP Export Vendor Template.xlsx",
"href": "/ACU19200/entity/DefaultExt/18.200.001/files/9479c468-1cfa-4fb5-b8bd-30c10535e525"
}
]
}
Now you need to take the “id” from the files section and get that file
var client = new RestClient("http://localhost/ACU19200/entity/DefaultExt/18.200.001/files/9479c468-1cfa-4fb5-b8bd-30c10535e525");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
As a result, you will get the file as application/octet-stream.
Upvotes: 3