Rest API - GET request help - Need help in constructing a URI with parameters - get

I am new to constructing Rest API GET queries.
Need help in GET request of Rest API by passing the fields in sysparm_fields.
I trying to query a Table via Rest API URI by passing only a limited number of columns of the table using Sysparam_fields.
However few column names have Spaces and parenthesis in it. So the JSON result set is excluding those columns and respective data when I do a GET request.
So if I am querying with column names "assigned_to (need the empid)" and "Number", I only get "Number" data.
If I dont pass, sysparm_fields it is returning the result set with all the columns including "assigned_to (need the empid)"
My end point looks like this
https://MyInstance.service-now.com/api/now/table/ticket?sysparm_exclude_reference_link=true&sysparm_fields=number,assigned_to (need the empid)&sysparm_query=sys_updated_onBETWEENjavascript:gs.dateGenerate('2020-09-01','00:00:00')#javascript:gs.dateGenerate('2020-09-01','23:59:59')
The result is only
{
"result": [
{
"number": "TK00001"
}
}
If my URI is
https://MyInstance.service-now.com/api/now/table/ticket?sysparm_exclude_reference_link=true&sysparm_query=sys_updated_onBETWEENjavascript:gs.dateGenerate('2020-09-01','00:00:00')#javascript:gs.dateGenerate('2020-09-01','23:59:59')
Then I get the result
{
"result": [
{
"number": "TK00001",
"assigned_to (need the empid)":"MYQ001",
"Other_Field1":"Other Value 1",
:
"Other_FieldN":"Other Value N"
}
}
So how do I pass the column names that has Spaces and parenthesis like "assigned_to (need the empid)"
Thanks for the Help in Advance

Related

How to send the output values of a Lookup activity in an email in Data Factory?

I'm trying to send a LookUp activity output values as part of a body parameter in a POST request using LogicApp, which uses three parameters: "to", "email_body", "subject".
The LookUp activity depends on a query, and it may return from 2 rows up to 10 rows.
According to Azure, the output of the activity should look like this:
{
"count": 2,
"value": [
{
"column1":value1,
"column2":value2,
"column3":value3
},
{
"column1":value4,
"column2":value5,
"column3":value6
}
]
}
In this case, the query returned 2 rows, but how can I attach every output value to the POST body without having to use #activity('lookup_act').output.value[0].column1 and so on for every value?
The POST body is the following:
{
"email_body": "Hi, the following tables have been updated:
#{activity('lookup_act').output.value[0].column1}
#{activity('lookup_act').output.value[1].column1}",
"subject": "Update on tables",
"to": "email#domain.com"
}
I've tried using #activity('lookup_act').output.value to bring every value but it won't work.
Is there a way to call every single output value? If so, how can it be done and paste into a table?
Thanks beforehand.
There are two ways to get all values in mail:
1. Get whole lookup output array in mail.
First get the results from Lookup activity and then pass the output of this activity by converting it into a string otherwise you will get error regarding deserialization.
{"message":"#string(activity('Lookup1').output.value)",
"dataFactoryName":"#{pipeline().DataFactory}",
"pipelineName":"#{pipeline().Pipeline}",
"receiver":"#{pipeline().parameters.receiver}"}
OUTPUT
2. Get all the respective values column wise.
First get the results from Lookup activity then take a foreach loop and create append variable for every column to store every column value in single array.
ForEach activity setting:
Took append variable activity and created Idarray variable. and gave item().id as value to store all id values in a single array.
Then in web activity passed below body for getting all arrays.
{"message":"#{string(variables('Idarray'))} as Id, #{string(variables('Namearray'))} as Name, #{string(variables('ProfessionArray'))} as Profession",
"dataFactoryName":"#{pipeline().DataFactory}",
"pipelineName":"#{pipeline().Pipeline}",
"receiver":"#{pipeline().parameters.receiver}"}
OUTPUT

I am having trouble parsing the JSON in livecode

I'm trying to create a simple mobile app that queries an API and parses the response to display certain values.
The mobile has 2 fields viz:
Button to query the api
Large text box to display the contents
In my livecode stack, I've the following inclusions:
JSON Library
mergJSON
tsNet
The api response is as follows:
{
"data": [
{
"id": 1,
"date_created": "2021-11-08T17:12:03Z",
"date_updated": "2021-11-22T16:08:55Z",
"first_name": "John",
"last_name": "Doe",
"email": "john.doe#unknown.com",
"phone": "9876543210",
"dob": "1980-01-01",
"password": "xxxxxxxxx",
"plan_start": "2021-11-22T16:07:46Z",
"plan_expiry": "2021-12-21T16:06:25Z"
}
]
}
I want to parse the JSON to display the email field value in the textbox.
In my livecode stack:
The button is named as "getdata"
The textbox is named as "flddata"
In the button script, I've added the following code:
put "<api url endpoint>" into tUrl
put "Authorization: Bearer xxxxxxxxx" into tHeaders
put tsNetGetSync(tUrl, tHeaders, tRecvHeaders, tResult, tBytes) into tData
put JSONToArray(tData) into tDataArray
put tDataArray["email"] into field "flddata"
But this doesn't work. Nothing happens. For the life of me, I can't figure out what's wrong. Any help would be appreciated. Thanks a ton!
To access the "email" key of the array that is built from the JSON you shared. You must first access the "data" key and then key 1. So the last line of your code would be as follows:
put tDataArray ["data"] [1] ["email"] into field "flddata"
Tips:
Put a break point on that line. This will allow you to see the contents of the variables so that you can see the structure of the array.
It looks like it might be a multidimensional array. Here's a simple way to get a look at how it's structured:
Drag a Tree View widget onto your card.
Set the arrayData property of the widget to your array tDataArray. Like this:
set the arrayData of widget "Tree View" to tDataArray
You should see the structure of the array in your tree view widget. It's possible that the array that was created looks something like this:
put tDataArray[1]["email"] into field "flddata"

how to compare 2 JSON files in Azure data factory

I'm new to Azure data factory. I want to compare 2 json files through azure data factory. We need to get new list of id's in current JSON file which are not in previous JSON file. Below are the 2 sample JSON files.
Previous JSON file :
{
"count": 2,
"values": [
{
"id": "4e10aa02d0b945ae9dcf5cb9ded9a083"
},
{
"id": "cbc414db-4d08-48f2-8fb7-748c5da45ca9"
}
]
}
Current JSON file:
{
"count": 3,
"values": [
{
"id": "4e10aa02d0b945ae9dcf5cb9ded9a083"
},
{
"id": "cbc414db-4d08-48f2-8fb7-748c5da45ca9"
},
{
"id": "5ea951e3-88d7-40b4-9e3f-d787b94a43c8"
}
]
}
New id's has to perform one activity and old id's has to perform another activity.
WE are running out the time and please help me out.
Thanks in advance!
You can simply use a IfCondition Activity
If expression:
#equals(activity('Lookup1').output.value,activity('Lookup2').output.value)
Further I have used Fail Activity for False condition for better visibility.
--
Lookup1 Activity --> Json1.json
Lookup2 Activity --> Json2.json
This can be done using a single Filter Activity.
I have assigned two parameters "Old_json" and "New_json" for your Previous Json and Current Json files respectively.
In the settings of Filter activity,
Items: #pipeline().parameters.New_json.values
Condition: #not(contains(pipeline().parameters.Old_Json.values,item()))
So, this filter activity goes through each item in New json, and checks if they are present in the old json. If not present, then will give that as an output.
Output of the filter activity
Thanks #KarthikBhyresh-MT for a helpful answer.
Just to add, if (like me) you want to compare two files (or in my case, a file with the output of a SQL query), but don't care about the order of the records, you can do this using a ForEach activity. This also has the benefit of allowing a more specific error message in the case of a difference between the files.
My first If Condition checks the two files have the same row count, with the expression:
#equals(activity('Select from SQL').output.count, activity('Lookup from CSV').output.count)
The False branch leads to a Fail activity with message:
#concat(pipeline().parameters.TestName, ': CSV has ', string(activity('Lookup from CSV').output.count), ' records but SQL query returned ', string(activity('Select from SQL').output.count))
If this succeeds, flow passes to a ForEach, iterating through items:
#activity('Lookup from CSV').output.value
... which contains an If Condition with expression:
#contains(string(activity('Select from SQL').output.value), string(item()))
The False branch for that If Condition contains an Append variable activity, which appends to a variable I've added to the pipeline called MismatchedRecords. The Value appended is:
#item()
Following the ForEach, a final If Condition then checks whether MismatchedRecords contains any items:
#equals(length(variables('MismatchedRecords')), 0)
... and the False branch contains another Fail activity, with message:
#concat(string(length(variables('MismatchedRecords'))), ' records from CSV not found in SQL. Missing records: ', string(variables('MismatchedRecords')), ' SQL output: ', string(activity('Select from SQL').output.value))
The message contains specific information about the records which could not be matched, to allow further investigation.

How to obtain nested fields within JSON

Background:
I wish to update a nested field within my JSON document. I want to query for all of the "state" that equal "new"
{
"id": "123"
"feedback" : {
"Features" : [
{
"state":"new"
}
]
}
This is what I have tried to do:
Since this is a nested document. My query looks like this:
SELECT * FROM c WHERE c.feedback.Features.state = "new"
However, I keep ending up with zero results when I know that this exists within the database. What am I doing wrong? Maybe I am getting 0 results because the Features is an array?
Any help is appreciated
For arrays, you'll need to use ARRAY_CONTAINS(). For example, in your case:
SELECT *
FROM c
WHERE ARRAY_CONTAINS(c.feedback.Features,{'state': 'new'}, true)
The 3rd parameter specifies that you're searching within documents within the array, not scalar values.

MS Graph - URL syntax for sorting Excel filtered rows

I am trying to retrieve sorted/filtered rows from Excel using Microsoft Graph API but no matter what URL structure (I tried many) I try, the results are not sorted.
The only way I managed was by sorting the original table (i.e. not using a workbook-session-id) but that is not an option for me. I must not affect the spreadsheet.
POST https://graph.microsoft.com/v1.0/groups/<groupid>/drive/root:/test.xlsx:/workbook/createSession
BODY => {persistChanges:false}
// retrieved the id
POST https://graph.microsoft.com/v1.0/groups/<groupid>/drive/root:/test.xlsx:/workbook/worksheets('test')/tables('test')/sort/apply
HEADER => workbook-session-id: session_Id
BODY => { fields: [{ key: column, ascending: false }], hasHeaders: true}
POST https://graph.microsoft.com/v1.0/groups/<groupid>/drive/root:/test.xlsx:/workbook/worksheets('test')/tables('test')/columns('description')/filter/apply
HEADER => workbook-session-id: session_Id
BODY => { criteria: { filterOn: "Custom", criterion1: "=" + filter, operator: "Or", criterion2: null } }
GET https://graph.microsoft.com/v1.0/groups/<groupid>/drive/root:/test.xlsx:/workbook/worksheets('test')/tables('test')/range/visibleView/rows?$select=values
The rows are returned filtered but not sorted. Ideally I would prefer to sort after filtering but I could not figure out the URL to use.
Excel API does not support sorting through the URL sort command. It has to be done at the file level. The persistChanges:false will ensure that file is not saved. Could you not sort, filter and get the visibleView from that series of action? Note that you still need to use the workbook-session-id header. It's just that when you set the persist change to false, the changes you make doesn't get saved to the server. However, you can continue to interact for the length of that non-persistent session. When you don't use the session Id, the request is treated as a persist command (though lot slower).

Resources