How “Send an HTTP request to SharePoint” action changes everything for SharePoint operations in Flow.

How “Send an HTTP request to SharePoint” action changes everything for SharePoint operations in Flow.

I was pretty much new to Microsoft Flow two months back and used to just know about a few basic actions and triggers in MS Flow. Majority of my tasks included my flow to interact with SharePoint.

Though we have a decent number of actions OOTB that allowed users to perform SharePoint Operations from Flow. But as a developer, these actions were not helpful for many operations like breaking permissions, moving the item to a folder and many more.

This is where I started missing the SharePoint REST calls. And after much exploration, I found that we didn’t have a capability to make SharePoint Rest calls directly. The only workaround was to do it via HTTP request.

Action2

But this approach will need you to get Authorization Token to build SharePoint context and then we can make our SharePoint HTTP request.

I realized that wasn’t this simpler in Workflow 2013, where I could make HTTP rest calls without much fuss. This made me think is Flow really an alternative to Workflow 2013? If so why it cant perform operations that Workflow 2013 could?

And to my relief, I found a pretty awesome action in SharePoint Connector i.e. “Send an HTTP request to SharePoint”. This totally changed my outlook towards flow. Now I am able to swim freely into the vast sea to SharePoint.

Action1

With this action, we can now make any REST call to SharePoint without worrying about fetching SharePoint Context or getting Authorization Token.

PS: For any query, you would still need to have permissions on the resource you are fetching.

 

Developing Azure Functions with Visual Studio

Developing Azure Functions with Visual Studio

Microsoft is coming up with various changes to its Azure platform. In the past few updates, it has made easy for the developers to create and develop azure functions using visual studio.

In this blog, we will see how to develop and debug azure functions in visual studio.

Before we start developing, we would need the following tools:

  • Visual Studio 2017
  • Postman or any other tool used for calling REST(for HTTP triggers).

Please make sure that you have latest “Azure Functions and Web Jobs Tools” installed with Visual Studio 2017.

You can verify that by going to Tools>Extension and Updates in Visual Studio. Check if there are any updates to Azure Functions and Web Jobs Tools.

2018-04-24_15-56-05

Let start by creating a new solution and project. Go to File>New>Project and select Cloud from the category and then select Azure Functions.2018-04-24_16-05-45

In the next window, you will be asked to select the version of Azure Function you want to create. Azure Function v1 uses .NET Framework and v2 uses .NET Code Framework.

Please note that v2 is currently in preview.

Next, we need to select the type of trigger we want. Select empty if you want to create Azure function later. For this example, I am selecting  HTTP trigger.

Those whose function would need data storage can select the appropriate option from the storage account. For now, we can select None.

Access Rights defines the Authorization level for your azure function. Select Anonymous if you want no authorization for your function.

2018-04-24_16-11-47

Once done with the selection, click OK to create the project and azure function.

Once the project is created, you can find a file in solution explorer with name Function1.cs.

If you want, you can change the filename. Please do remember to change class names in the file too.

The Function1.cs file will look like below

2018-04-24_16-33-01

Run the project by pressing F5 or Debug>Start Debugging. It will open a console window emulator, which will set up the local Azure environment for the azure function.

Once the emulator fully complies, it will display all the azure functions running with the emulator. Since we have only one function, we can see only one function URL.

2018-04-24_16-37-34

Open Postman or any other tool for Rest. Use the URL provided in the emulator to trigger the function.

You can pass parameters in a body or as a query string. You need to write logic to parse them.

You can also log messages/error in the emulator by using log object.

Developing Azure function in Visual Studio gives the developer control and OOTB benefits of Visual Studio.

Few of the  benefits are:

  • The Function can be debugged for errors.
  • Various external packages can be added using NPM.
  • No need to use #r for referencing and assembly. It can be directly be referenced by “using” keyword.
  • The function can directly be published to Azure Resource.

 

Happy Coding.

 

Azure Queue with Azure Functions – Part I

Azure Queue with Azure Functions – Part I

We are all aware of how much powerful and useful can Azure function can be. But it is more astonishing to know that it can be more powerful if we use Azure Queue with it.

In this blog, I will focus on how to integrate Azure Queues with Azure functions/Timer trigger.

If you want to know more about Azure Queue and Azure Function individually then please first check the below links:

Before moving forward, we will need an Azure account. We can create a free account or use pay-as-you-go or any subscription if we have.

Let get started by first creating the Azure Function by selection New(new) and search for function app. Once we get the app click on create. We will get a popup as shown in below figure.

Azure1

We will fill the details for the app and click on create.

Once the app is created, we can navigate to the app. At first, there would be no functions. We need to create a function to process Azure Queues.

We will first create an Azure Timer Trigger which will create a message in Azure Queue.

Left Pane

We will create the Function by clicking the + sign beside Functions and then select Timer with C# and click Create the function.

CreateFunction

Once the Timer Function is created, we will get code editor opened for the Timer Function as shown below.

TriggerFunction.PNG

We will now try to get the output in Azure Queue. We will start by setting up our output variable. We will do this by clicking on integrate (Intigrate).

We will see options opened in the right pane of the page.

RightPaneWindow

We will now add the new output by clicking the “New Output” button and selecting Azure Queue Storage from the shown screen.

RightPaneWindow2Click Select to select the output variable type.

After we select, we will find the below screen displayed.

RightPaneWindow3

We need to provide three details to create the output variable:

  1. Message parameter name: It will be the name for our output variable.
  2. Queue name: This will be the Queue where our message will be stored. If the Queue does not exist, it will create the Queue.
  3. Storage account connection: In this, we need to select the storage where will our Queue be stored. You can create a new storage account by click on new.

Once we are done with providing the info, we will click on save to save our output variable details. After we save we can see our output variable in Outputs.

Outputsave

We will now come back to our code editor.  We will first create a QueueMessage class which will the data type for our output variable.

public class QueueMessage{
   public string Message{get;set;}
   public string Time{get;set;}
}

Message and Time are the default property of Azure Queue Message.

After creating the class, we will add the variable as an output parameter to the Run function.

Let us create an object of type QueueMessage and store dummy text in the message and time will be the current time. After we assign the values to the object, we will pass it to the output variable. After the changes, our code will look as below.

using System;
public static void Run(TimerInfo myTimer, TraceWriter log,out QueueMessage outputQueueItem){
   var date=DateTime.Now.ToString("hh:mm:ss");
   var queueItem=new MyQueueItem();
   queueItem.Time=date;
   queueItem.Message=date;
   outputQueueItem=queueItem;
}
public class QueueMessage{
   public string Message{get;set;}
   public string Time{get;set;}
}

When we run the function, a Queue Message will be created in the QueueStorage>Queue.

We can verify the data by Cloud Explorer in Visual Studio 2017.

We will see that in our next part of the blog.

Azure Queue with Azure Functions – Part II