Tuesday, 10 June 2025

Get SharePoint search results using the Rest API in PowerAutomate

In this blog, we will be learning about how to get SharePoint search results using the Rest API through PowerAutomate flow. The search results will be exported into a CSV file and saved into a SharePoint library. 

Create Flow

1). Sign in to Power Automate

2). Open the flow, click on the Create option, and select "Instant Cloud Flow".

Enter Flow name.
Choose the flow trigger as "Manually trigger a flow".
Click on the Create button.



3). Add an action "Send an HTTP request to SharePoint".


Site Address
https://yoursite.sharepoint.com/sites/VideoHub
Method
GET
Uri
_api/search/query
?querytext='Path:https://yoursite.sharepoint.com/sites/VideoHub*'
&trimduplicates=false&rowlimit=500
&selectproperties='Title,RefinableString00,RefinableInt00,
                   IsDiscontinued,RefinableString03'
&refiners='contentclass,SecondaryFileExtension,ListID'
&refinementfilters='and(
    contentclass:equals("STS_ListItem_DocumentLibrary"),
    SecondaryFileExtension:or("mp4","mkv"),
    ListID:equals("f7fb8ca6-aaaa-bbbb-cccc-7816d24bdf42")
)'
&sortlist='Created:descending'
Headers
{
  "accept": "application/json; odata=nometadata"
}


4). Add an action "Parse JSON" and enter output of previous step in Content.
In the Schema field use the below JSON content.


Parse JSON - Schema

		

Add additional type null - this will take care of the null values coming in search results.


5). Initialize variables one of type Object and Array.


		


6). Add "Apply to each" loop for rows and enter step 4 output (or enter below) as input value.

body('ParseJSONtoGetRows')['PrimaryQueryResult']['RelevantResults']['Table']['Rows']

Add another nested "Apply to each" loop for cells and enter current cells value (or enter below) as input value.

items('Apply_to_each-Rows')['Cells']


7). Add a "Switch" condition and enter current cell key value (or enter below) as On value.

items('Apply_to_each-Cells')?['Key']


8). Add a case statement to fetch field value from the search property.

Enter search managed property Title in equals field.

Add an action "Compose" and add below value in the inputs parameter.

setProperty(variables('varResponseJson'),'Title',items('Apply_to_each-Cells')?['Value'])

Here, setProperty(object, property, value) function is used; it returns an object with a property set to the provided value.

Add an action "Set variable" (defined in step 5) object variable and enter previous step output as input value.

9). Add more case statements; we are fetching five field values from the search properties. Therefore, five case statements are needed.
Repeat the step 8 for all the required search managed property.

Note: Create search managed properties for your custom fields and use them.




10). Append the array variable (defined in step 5) and enter object variable output as value after closing on inner "Apply to each" loop.


11). Add an action "Create CSV table" and enter array variable in From and Automatic in Columns.


12). Add an action "Create file" to create CSV file to export the search results.

Enter the Site Address and Folder Path as required.

File Name as concat('BlogData_', formatDateTime(utcNow(), 'yyyyMMdd_HHmmss'), '.csv')

File Content as output from previous step 12.



I hope this will help all of you! 🧲
Feel free to provide feedback.


🚀 "Happy Coding" 🚀

Monday, 10 February 2025

Get ServiceNow incident data using OAuth in Postman

In this blog, we will be learning about how to get ServiceNow incident ticket details using OAuth authentication in Postman.

Please follow the below steps:

Register OAuth application in ServiceNow

Before using OAuth in Postman, we must set up an OAuth provider in ServiceNow. Here's how to do that:

1). Log in to your ServiceNow instance as an administrator.
2). Open System OAuth > Application Registry.



3). Click on New and select Create an OAuth API endpoint for external clients.


4). Fill in the necessary fields:

Name: A descriptive name - "Postman OAuth App".
Client ID: A unique identifier for your application.
Client Secret: A secret key generated for your app.


5). Save the record and take note of the Client ID and Client Secret as you'll need them in Postman.

Get OAuth Token in Postman

Once your OAuth application is registered in ServiceNow, you'll use it to obtain an access token in Postman.

1). Open Postman.
2). Set the HTTP Method to POST.
3). Request URL is https://dev29xxxx.service-now.com/oauth_token.do
4). Go to the Body tab.
5). Fill in the details:

Key Value
grant_type password
client_id 58au69vbbe3771xxx2ab5793c46cd2xxxbb
client_secret Vb!2,69C5V|fAU
username admin
password AwdVmIseR4h*J4@

6). Click Send button to obtain the token.


Make a Request to Get Incident Data

1). Open Postman.
2). Set the HTTP Method to GET.
3). Request URL is:

https://dev29xxxx.service-now.com/api/now/table/incident?sysparm_limit=5&sysparm_query=active=true^ORDERBYDESCnumber&caller_id.email=david.miller@example.com&sysparm_fields=number,sys_created_on,urgency,state,short_description

4). Go to the Headers tab.
5). Fill in the details:

Key Value
Content-Type application/json
Accept application/json
Access-Control-Allow-Origin *
Authorization Bearer [access_token_value]

6). Click Send button to obtain the token.


View the Response

If everything is configured correctly, Postman will return a JSON response with the incident data from ServiceNow.


I hope this will help all of you! 🧲
Feel free to provide feedback.

Thursday, 2 January 2025

Migrate from an existing Run As Account to Managed identities

In this blog, we will be learning about migrating from an existing 'Run As Accounts' to Managed identities.

Sign in to the Azure portal with an account that’s a member of the subscription Administrator role or a Co-Administrator of the subscription.

The managed identities are of two types system assigned or user assigned.


Steps to be followed to migrate an existing 'Run As Accounts' to Managed identities:

Step 1: Identify the 'Run as accounts' getting expired.


Step 2: Check current role assignments for 'Run as account'.

Click on Run As Account from the screen above, it will show properties of it and at the bottom it will list out the roles.


Step 3: Create System Assigned Managed Identity.

Now we need to create the Managed Identity to migrate to. Go to the Automation Account and select Identity in the left navigation. It will allow to create a new System assigned, or User assigned managed identity.

Create a new System assigned managed identity. Click On and save it, Azure will automatically create the managed identity.


Once it finishes creating the managed identity, we can see the Object ID. Now, we can begin assigning permissions.


Step 4: Assign permissions to Managed Identity.

Click on Azure Role Assignments on the newly created managed identity. Add the same permissions (Step 2) as existing RunAs account had.


Once finished, we can see the role assignments assigned to the new managed identity (it will take some time to display roles assigned).


Step 5: Update credentials

Go to the Automation Account and select Credentials in the left navigation.


Select and update the Password and Confirm Password with App Secret value.
(Open App Registrations and create new client secret. Copy the client secret value and use it above)

Select Save.



⊛ Note

No need to do any changes in the Runbook code to use managed identities.


Step 6: Delete the 'Run As Account'

The final task is to clean up the RunAs resources. Go to the 'Automation Account' > 'Run As Accounts' and then click Delete.


Once finished, we will see that our existing automation account no longer has any Run As Accounts tied to it. It will also be deleted from the Azure Active Directory (AAD).



Refer Microsoft documentation for more
https://learn.microsoft.com/en-us/azure/automation/migrate-run-as-accounts-managed-identity


I hope this will help all of you! 🧲
Feel free to provide feedback.