February 25, 2021

Call SharePoint Rest API with Client ID and Client Secret from Power Automate

Overview:

We recently implemented an automated approval process in SharePoint Online with Power Automate for a construction and engineering company based out of Washington, United States. We came across a scenario where we required to consume SharePoint data in Power Automate with REST API using Client ID & Client Secret. Here in this article, we will discuss step by step process to implement such functionality.


Prerequisite:

We must have SharePoint App registered, please visit this article for step by step process to register the SharePoint App.

Copy Tenant ID from Azure Portal:

  1. Open Azure Portal. From Left Navigation click on Azure Active Directory
  2. Here, you will get your Tenant ID.

Steps to call SharePoint REST APIs with Client ID and Client Secret from Power Automate (MS Flow)

  1. Initialize variables for – Client ID, Client Secret, Tenant Name and Tenant ID.
    1. Client ID and Client Secret = We can get these from where we registered the App.
    2. Tenant Name = Name of the Tenant.
    3. Tenant ID = We can get that from Azure Portal (Step 2 from above section).
  2. Prepare Body Variable.
     grant_type=client_credentials&client_id=<<Client ID>>@<<TenantID>>&client_secret=<<Client Secret>>&resource=00000003-0000-0ff1-ce00-000000000000/<<TenantName>>.sharepoint.com@<<TenantID>>   
    
  3. Now, add “HTTP action”.
    1. Method: POST
    2. URI: https://accounts.accesscontrol.windows.net/@{variables('tenantID')}/tokens/OAuth/2
    3. Headers:  Content-Type: application/x-www-form-urlencoded
    4. Body: Pass the variable defined in Step 2.
  4. Get Access token in Compose Variable.
    Expression: body('Get_Access_Token_from_SharePoint')['access_token']
  5. Add HTTP Action to get users from SharePoint group.
    1. Method: Get
    2. URI: https://tenantname.sharepoint.com/sites/sitename/_api/web/sitegroups/getbyname('groupname')/users
    3. Headers: 
    4. Accept: application/json;odata=verbose
      Authorization: Bearer @{outputs('Compose')}
  6. Then, let’s Parse our JSON using Select Statement.

This is how we can create a flow to find the users from SharePoint Group with client Id and client secret. 


Test Flow

The flow ran successfully.
We got the following access token using first API call.
Then this access token used to call the group users. We got the following users.


Conclusion:

This is how, we can call SharePoint Rest API with Client ID and Client Secret from Power Automate. Isn’t that amazing? 

If you have any questions you can reach out our SharePoint Consulting team here.

[Issue Resolved]: Part URI is not valid per rules defined in the Open Packaging Conventions specification

Introduction

We at Binary Republik recently implemented Intranet Portal on Modern SharePoint for a Real Estate Agency based out of Washington, United States. We also implemented custom webparts with SharePoint Framework (SFPx) as part of the Intranet Portal implementation to meet the business user expectations. While implementing the custom SFPx webparts, we encountered a strange error. Let's see in detail what error we faced in which scenario, what was the root cause of the error and what's the resolution for the same. 


Error/Issue:

  • After uploading the ".sppkg" solution of SPFx webpart in the "app catalog", it was giving the error “Invalid SharePoint App package. Error: Part URI is not valid per rules defined in the Open Packaging Conventions specification”.


Scenario:

  • We created SPFx webpart solution, the solution was built successfully. Then we executed the below commands to create package:
    • gulp bundle --ship
    • gulp package-solution –ship
  • The package was also created successfully, so we uploaded the same to the "app catalog" and it was giving an error as shown above.


Reason:

  • After some research and analysis, we found, this was because of the parent folder of our SPFx webpart solution.
  • Here is the path of our solution: D:\Projects\Project Management
  • The parent folder name of our solution was "Project Management" (please note, there is a space in the name of the parent folder) and while creating the solution we have selected the option to "Use the current folder" in "Where do you want to place the files?" selection.

  • So, when there is space in the name of the parent folder of your solution, it will give the error “Error: Part URI is not valid per rules defined in the Open Packaging Conventions specification”.


Solution:

  • To solve this error, remove space from the name of the parent folder of your solution. We renamed the parent folder name to be “ProjectManagement”.
  • Then executed below commands:
    • gulp clean
    • gulp build
    • gulp bundle --ship
    • gulp package-solution –ship
  • And deployed the new package in the "app catalog" and the package was deployed successfully.


Hope this helps!
 
If you have any questions you can reach out our SharePoint Consulting team here.

February 18, 2021

Update SharePoint Hyperlink fields with URL and Description using Power Automate (MS Flow)

Introduction

We recently implemented an automated approval process in SharePoint Online using Power Automate for the HR department of an Engineering Company based out of Denmark. We came across a scenario wherein it was required to update the value of the Hyperlink field in the SharePoint list with URL & Description from Power Automate.

Problem Statement

We cannot directly update the value of the Hyperlink field with description from using "Update Item" action in Power Automate (MS Flow). So in this article, we will see how to update the value of the Hyperlink field with URL & Description using HTTP Request Action in Power Automate.

Resolution

As an alternate, we can use "Send an HTTP request to SharePoint" action in Power Automate to update the value of the Hyperlink field with URL & Description in SharePoint. Let's see the step by step process to perform the same, for easier understanding we will go with an example SharePoint List with a straightforward scenario.

SharePoint List

We have already created a SharePopint List with two fields Title (Single Line of Text) and Address (Hyperlink).


Steps to Follow

Step 1: Open your flow and add "When an item is created" trigger and provide your "Site Address" and "List Name".


Step 2: Add a new action "Send an HTTP request to SharePoint".



Step 3: Once successfully added, provide all the details as required.


Site Address: Your Site Address

Method: POST

Uri :  _api/web/lists/GetByTitle(‘ListName’)/items([ID]). (Update “ListName” to your list’s name & replace “[ID]” with the ID field from dynamic content).

 

Step 4: Click on “Text Mode” in "Send an HTTP request to SharePoint" action.



Step 5:  Add the below code in the Header Textbox.
1:  {  
2:  "Content-Type": "application/json;odata=verbose",  
3:  "X-HTTP-Method": "MERGE",  
4:  "IF-MATCH": "*"  
5:  }


Step 6:  Add the below code in Body Textbox

1:  {'__metadata': {'type':'SP.Data.RecordsListItem'},  
2:  'Address':{'Description': 'Click Here','Url': 'https://www.msn.com'}  
3:  }  


Step 7: Replace 'SP.Data.RecordsListItem’ with ListItemEntityTypeFullName of the list. We can use "<Site URL>/_api/web/lists/GetByTitle('<List Name>')?select=ListItemEntityTypeFullName" endpoint to know ListItemEntityTypeFullName for a specific SharePoint List.

Step 8: Replace 'Address' with the name of your  hyperlink column name

Step 9: Replace 'Description' text with the label/description text you want for the link

Step 10: Replace https://www.msn.com with your hyperlink.


Output

When a new item is created in the SharePoint List, the Hyperlink Field value gets populated with Description from Power Automate (with values configured in Power Automate).


Hope this helps!

If you have any questions you can reach out our SharePoint Consulting team here.