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

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 ...

Related

Azure data factory - custom mapping for Rest service

So, I am creating a Copy activity that reads from SQL Server table and have to send the data to an API end point with the PATCH request.
API provider specified that the body must be in the form of
"updates":[{"key1":"value1","key2":"value2","key3":"value3" },
{"key1":"value1","key2":"value2","key3":"value3" }, ...
.... {"key1":"value1","key2":"value2","key3":"value3" }]
However, my sql table maps to json this way (without the wrapper 'updates:')
[{"key1":"value1","key2":"value2","key3":"value3" },
{"key1":"value1","key2":"value2","key3":"value3" }, ...
.... {"key1":"value1","key2":"value2","key3":"value3" }]
I use the copy activity with the sink data set being of type Rest ..
How can we modify the mapping, so that schema gets wrapped by "updates" object ?
Using copy data activity, there might not be any possibility to wrap the data (array of objects) to an updates key.
To do this, I have used a lookup activity to get the data, set variable activity to wrap the data with an updates object key and finally, use Web activity with PATCH method and above variable value as body to complete the activity.
The following is the sample data I have taken for my SQL server table.
Use look up activity to select the data from this table using table or query option (I used query option). The debug output would be as follows:
NOTE: If your data is not same as in sample table I have taken, try using the query option so the output would be something as shown below
In the set variable activity, I have used an array variable and used the following dynamic content to wrap the above array of objects with updates key.
#array(json(concat('{"updates":',string(activity('Lookup1').output.value),'}')))
Now in the Web activity, choose all the necessary settings (PATCH method, authorizations, headers, URL, etc.,) and give the body as follows (I used a fake REST api as a demo):
#variables('tp')[0]
Since I am using the Fake REST API, the activity succeeds, but checking the Web activity debug input shows what is the body that is being passed to the Rest API. The following is an image for reference:

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

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.

How to use Moodle REST API Call mod_data_add_entry (and parameters)?

I'm trying to set up a webpage that communicates with a Moodle page. I need different data from a database activity and want to create new entries. Note that I am not talking about the SQL database in BG, it is the activity database in courses.
The information should be retrieved/transferred via the REST API, an HTML POST Request. My problem is that I don't know how to add a new record to the database activity because I cannot transfer the data array. Only the first parameter given appears in my database.
E.g. i tried ...&wsfunction=mod_data_add_entry&databaseid=10&data[0][fieldid]=66&data[0][value]=12&data[1][fieldid]=67&data[1][value]=test
And many other combinations. Always only the first parameter is shown in the database.
The docs tell me this (Pseudocode):
//The fields data to be created
list of (
object {
fieldid int //The field id.
subfield string Default to "" //The subfield name (if required).
value string //The contents for the field always JSON encoded.
}
)
Alternatively:
REST (POST parameters)
data[0][fieldid]= int
data[0][subfield]= string
data[0][value]= string
I cannot find anywhere else something called a "subfield".
Any ideas?
Okay, found it. You have to put your values in "", unless they are not a number. Seems like there is a connection with this special activity because you don't have to do it elsewhere.

Salesforce API - Using Compound fields. (Cannot deserialize instance of MailingAddress from VALUE_STRING)

Using REST API for Salesforce, I am trying to insert/update a contact into my business org where 'MailingAddress' is one of the fields with some set data, though in response I am getting this error message 'Cannot deserialize instance of MailingAddress from VALUE_STRING', the same response also resulting in 'OtherAddress'.
To my understanding, I think this is due to the reason that 'MailingAddress' and 'OtherAddress' are not actual fields that contains some String data, rather they take a dynamic address which resulting in filling up all other related fields like - 'MailingCity, MailingStreet, etc'.
So I have 2 questions:
1. How can I set 'MailingAddress' and 'OtherAddress' fields using API parameter only?
2. Is there any manual/documentation for this reference? As I am also having trouble with 'OtherLatitude' and 'OtherLogitude' fields.
Address and geolocation fields are compound fields.
You need to provide the value for the different components of the field, so for example, for MailingAddress you would need to provide MailingStreet, MailingCity, MailingState or MailingStateCode, etc. And for OtherAddress you would provide OtherStreet, OtherCity, etc.
For more information on compound fields: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields.htm

PUT multiple related records in Data API request

In the documentation from FMI the HTTP-body example for creating records using FMS16 Data API (REST) looks like this
{"data":
{
"field_1": "value_1",
"field_2": "value_2",
"repetitionField(1)" : "fieldValue",
"Orders::OrderDate.0":"12/22/2015"
}
}
The last attribute Orders::OrderDate.0 sets a value to a field on a related record and since the record don´t already exist it will be created.
My question focus on the .0 suffix of the attribute name. It looks to me like the 0 indicates a serial/identifier for on which related record the value should be inserted. This leads me to wonder if it is possible to create more then one related record in the same request that creates the parent record.
The below body returns error that the record does not exist, but why can one related record be created but not two?
{"data":
{
"field_1": "value_1",
"field_2": "value_2",
"repetitionField(1)" : "fieldValue",
"Orders::OrderDate.0":"12/22/2015",
"Orders::OrderDate.1":"11/11/2011"
}
}
Any clue if the above code should work? Am I missing something?
I am fully aware that I can (should) post several requests aimed at the related tables layout to create the related records. I just wish to know, since the .0 notation is in the documentation, does it should have a valid function?
Found this under the notes section in the doc you linked to:
"Only one related record can be created per create record call."
So there you have it. Looks like it behaves similarly to record creation from a portal, where you also can only create one related record at a time.