Determine Correct JSON Fields for REST API based on Endpoint and Screen names (Customers & Sales Orders) - Acumatica - rest

My project is to import Customers and Sales orders. I take a CSV file from an external program, and am to import them -- field by field -- into Sales Orders and Customers.
My challenge is determining the correct field names to get the REST API to work correctly.
I have the following fields:
I am looking to include the three fields: Description, Gift Message, and Public Comment. I inspect the element, which gives me nothing useful that I can tell. (i.e. none of the values map to the field name that I would use in JSON.)
When I go to the Endpoint for Customers, Description already exists:
And therefore, this JSON Record succeeds in an ADD or UPDATE:
{
"OrderNbr" : {"value": "SO003525"},
"Description" : {"value": "This is the Description"},
}
I extend the default customer (version 18.200.001) and I find and add the "Gift Description" and the "Public Comments" -- and they are listed as part of the "Order Summary" -- which is exactly where Description was.
However, this JSON data does add anything to Gift or Public:
{
"OrderNbr" : {"value": "SO003525"},
"Description" : {"value": "This is the Description"},
"PublicComment" : {"value": "This is the Public Comment"},
"GiftMessage": { "value": "This is the Gift Message"},
}
In talking to the (in-house) developer who set up the screen, he told me that the "Gift Message" and "Public Comments" fields were added on. But they are not showing as "User Defined" fields in the Endpoint.
Questions:
1) How can I know what the JSON structure should look like? Is there some sort of a mapping document, or a printout that shows JSON-to-Endpoint data? What I mean is that sometimes I need to use a sub-object to reference data in JSON, for example, if I want to update "Main Contact" information, I do it like this:
{
"CustomerClass":{"value":"INDIVIDUAL"},
"CustomerID":{"value":"78577"},
"CustomerName":{"value":"TEST CUSTOMER "},
"MainContact":
{
"CompanyName":{"value":"TEST CUSTOMER COMPANY"},
"DisplayName":{"value": "TEST CUSTOMER DISPLAY"},
}
}
How can I know to do that? (I know only because I saw it in the data that got returned when I added a record... Which brings up a second question:
2) Is there a way for retrieving an entire data record in its JSON format. Sort of like a : "GET - SELECT ALL - EXPAND ALL" so I can see all of the data in a record in a properly set up JSON format?
3) Any idea why the gift Message and Public Comments are showing as "Order Summary" but aren't updating like Description is?
4) Why are some things "un-expandable?" For example, I cannot expand Payments in Sales Order. I get an error:

1) How can I know what the JSON structure should look like
The easiest way is to execute a GET request. The field names are equivalent to the DisplayName property stripped of whitespaces. So if on screen the field is labelled Order Type the field name will be OrderType in the request.
To make a GET request, the URL format is /Entity/Keys.
For example entity SalesOrder has two keys: OrderType and OrderNbr.
To get entity SalesOrder of type SO and with the number SO005051 the URL would end with: /SalesOrder/SO/SO005051.
2) Is there a way for retrieving an entire data record in its JSON
format. Sort of like a : "GET - SELECT ALL - EXPAND ALL" so I can see
all of the data in a record in a properly set up JSON format?
If you want all the details, you need to specify them all in the expand clause of the GET query: $expand=Contacts,MainContact,BillingContact
The name of the details array can be looked up in the Web Service Endpoint screen SM207060. They are the tree view elements with a empty array [] suffix.
3) Any idea why the gift Message and Public Comments are showing as
"Order Summary" but aren't updating like Description is?
Those are custom fields. You need to extend the endpoint to add those custom fields otherwise they will be ignored. If there's no issue with the custom endpoint maybe the field aren't bound to database.
But they are not showing as "User Defined" fields in the Endpoint.
If by User Defined you mean those fields were added with a wizard (without programming) then this is likely the reason why they don't work in the web service. You would need to add custom field with a DAC extension which requires programming instead of the User Defined field.

Related

Translating a GUID to a text value, from an API response in a Power Automate Flow

I'm using MS Automate to solve an integration challenge between two systems we use in our Project Management lifecycle. I have a custom connector written by the vendor of System A which allows me to create a Flow in MS Automate which is triggered when a record is Created or Updated.
So far, so good. However, the method in the connector provided by System A returns the new or updated record containing a number of fields which contain value GUIDs as the fields are 'choice' type fields e.g. Department, Status etc. What I end up with is a record where Status = "XXXXXX-000000-00000-00000" etc. The vendor also provides a restful API endpoint which I can query, which returns a JSON collection of fields, which include a 'Choices' section for each field of this type which is a standard JSON which looks like:
{
"Id": "156e6c29-24b3-4413-af91-80a62a04d443",
"Order": 110,
"InternalName": "PrjStatus",
"DisplayName": "Status",
"ColumnType": 5,
"ColumnAggregate": 0,
"Choices": {
"69659014-be4d-eb11-bf94-00155df8457c": "(0) Not Set",
"c30c50e5-51cf-ea11-bfd3-00155de84703": "(1) On Track",
"c40c50e5-51cf-ea11-bfd3-00155de84703": "(2) At Risk",
"c50c50e5-51cf-ea11-bfd3-00155de84703": "(3) Off Track",
"6a659014-be4d-eb11-bf94-00155df8457c": "(4) Not Tracked"
},
Technical problem:
What I have is the GUID of the choice (not the field). I need to take the GUID, in this case "6a659014-be4d-eb11-bf94-00155df8457c" and translate it into "(4) Not Tracked" and store this in a variable to write to a SharePoint list. I need to do this for about 30 fields which are similar in the record.
I've created the flow and the connector has given me the record with a list of fields, some of which contain value GUIDs. I know which fields these are and I have the Display Names of these fields.
I have added a HTTP call to the provided API endpoint (lets call it GetFields), which has returned a 200 response, the body of the response containing a JSON collection of the 50 or so fields in System A.
I can't work out how to parse the body of the response for the GUID I have for each field value and ensure I have the right corresponding text value, so I can then write it to a field variable, and then create a SharePoint record, all wrapped up in an MS Automate flow.
I hope I've understood you correctly but from what I can work out, you want to dynamically select the value of the choice from the GUID you've been provided (by whatever means).
I created a small flow to prove the concept. Firstly, these two steps setup the scenario, the first being the GUID you want to extract the choice value for and the second being the JSON object itself ...
The third step will take the value from the first variable and use it dynamically in an expression to extract that key from the JSON and return the value.
This is the expression ...
variables('JSON')?['Choices'][variables('Choice ID')]
You an see I'm just using the variable in the path expression over the top of the JSON object to extract the key I want.
This is the end result ...

Using Logic Apps, how can I input a formatted Table of results from an SQL Stored Procedure into SendGrid Email

Once a day, I need to run an SQL Stored Procedure, which collects a list of results. I then need to input the results, as a nice user friendly table, into an e-mail (SendGrid).
So far, I have setup all connections and got the Logic App to work but the e-mail it generates displays the results like this:
{"Table1":[{"CaseID":"1000001","DateOfUdate":"2020-06-09T11:34:57.483"},{"CaseID":"1000002","DateOfUdate":"2020-06-09T11:34:57.483"},{"CaseID":"1000003","DateOfUdate":"2020-06-09T11:34:57.483"},{"CaseID":"1000004","DateOfUdate":"2020-06-09T11:34:57.483"}]}
How can I get this to be displayed as a proper table?
Case ID DateofUpdate
1000001 2020-06-09T11:34:57.483
1000002 2020-06-09T11:34:57.483
1000003 2020-06-09T11:34:57.483
1000004 2020-06-09T11:34:57.483
Below are images of my Logic App - please let me know if I need to provide more information.
For this requirement, please refer to the steps I provided below:
1. I initialize a variable named "resultSetVar" and store the json data same to yours', use this variable to simulate your "ResultSets" data.
2. Then use "Parse JSON" action to parse the json data.
3. After that, use "Create HTML table" action to create the html with the json array "Table1" from the "Parse JSON" action.
4. At last, put the "Output" from "Create HTML table" action into the "Email body" box.
5. Running the logic app, I received the email shown as below
Hope it helps~

SurveyMonkey Email Collector Custom Values

In order to include information (like an order number) in a survey using an Email Collector, it's my understanding that this information needs to be stored in the Contact's custom variables. My concern is what happens if I am sending something like a customer satisfaction survey that needs to reference the order number, and the same customer (email address) places more than one order, and I have to send out more than one survey.
Will the custom values that are returned with the collectors/.../responses API call include the custom values at the time of the survey invite? Or will these be set to current values?
The custom values are stored on the response at the time the survey is taken. So if they change later, they will not change on the response. This will work fine as long as you don't sent out another survey with new custom values to the same contact before they respond to the previous one.
Just an FYI, there is also an option to set extra_fields on a recipient when adding recipients to an email collector (rather than on the contact).
POST /v3/collectors/<collector_id>/messages/<message_id>/recipients
{
"email": "test#example.com",
"extra_fields": {
"field1": "value1",
"field2": "value2"
}
}
I don't believe that data is stored with he response, but the recipient_id is and you can fetch the recipient by ID to get that data back.
Those are two options, you can see which one works best for you. The benefit of contact custom values is that you can view them and edit them from the web, whereas extra_fields are API only fields.

How do I export GLBudgetLineDetail via Rest API?

My goal is to export data from the [GLBudgetlineDetail] table via the Rest API.
To accomplish this:
1) I created created a custom endpoint based on the Budgets screen (Finance > General Ledger > Work Area > Enter > Budgets)
!(http://imgur.com/sQC0zOI)
2) I populated the endpoint by adding all the fields from the Budget Articles container
!(http://imgur.com/tZp2GMh)
When I query this endpoint, I only get an empty array returned "[]".
Here is the query:
GET http ://servername/WebServiceAPITest/entity/MyStore/6.00.001/Budget
Headers:
Content-Type -> application/json
("Budget" is the name I gave to the endpoint)
I can successfully query other endpoints (Accounts, Vendors, JournalTransactions, etc) but I can't get any data back from this one.
I created the MyStore Demo (Course I210) and have access to the [GLBudgetLineDetail] table and can verify that it has data. On the Budgets screen, if I filter to year 2013, Ledger 'Budget', Branch 'SOFT', I can see Budget information.
How do I get access to this info via the Rest API?
Since you mentioned the Course I210, You might want to refer yourself to the section 3.4.1 about Retrieving the Price of an Item for a Customer.
In that section, they are saying that if you want to retrieve data from an inquiry, you must use the Put command:
"Because you are retrieving the price of an item from the inquiry, you will use the Put() method to obtain data."
Since the Budget Screen is an Inquiry Screen you must use the Put command to set the parameter you want.
Here is one that I tried and that worked on an Acumatica web site with demo
data:
PUT http://localhost/Demo610u04/entity/BudgetEndpoint/6.00.001/Budget
Headers (Key -> Value):
Content-Type -> application/json
Accept -> application/json
Body :
{
"BudgetArticles":[{}],
"FinancialYear":{"Value":"2016"},
"Ledger":{"Value":"BUDGET"}
}
EDIT: Looking at the image you added, you should have your budget Filter fields in the main entity and have a sub entity of type Detail containing the Budget Articles fields

Setting up user form in a Web Client for a REST API

I having trouble trying to figure out a standard "best-practice" to handle forms for a web application that interacts with a REST-like service.
For Example:
There is a registration/updating form for users, the UI require the user to specify the following fields
Name: Input field
Age: Input field
Country: Select Field
This functionality relies on two uris patterns
/user/{user_id} : In order to GET, POST, DELETE and PUT information about users
/country/ : This helps filling up the available options for the "Country" select field of the form it comprises a "Contry Id" (option value) and a "Country Name" (option text)
When a new user enters the registration forms the "Country" select input options are populated with the info of /country, then the user fills the form the data that is being POST to /user/
When a user is being edited the form has to be initialized with the user info, this requires two requests (one for the select list and another for the user data).
In this case, initializing the form is pretty easy but complex when considering populating too many "list"-like form controls.
What would be the best way to handle "form setup" (list options, radios, combos, checkboxes) and "resource data load" (the entity data)?
thanks