Creating a Nintex Workflow Cloud Xtension using a C# Azure Function

This is a little addendum to the previous post : http://workflowexcellence.com/creating-a-nintex-workflow-cloud-xtension-using-a-javascript-azure-function/

Since I’ve done a lot more C# dev than Javascript, I started looking into how to built an Azure Function using C#.

Below is one such function that does a Trigonometry Sin calculation.

The idea is to show how pass in information from a Query String or Body, use that to then do a Calculation and return the result that will eventually come out as JSON, with “result” being the key name.

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info(“C# HTTP trigger function processed a request.”);

    // parse query parameter
    string angle = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, “angle”, true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    angle = angle ?? data?.angle;

    return angle == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, “Please pass a angle on the query string or in the request body”)
        : req.CreateResponse(HttpStatusCode.OK, “{ \”result\”: \”” + Math.Sin(Convert.ToDouble(angle)) + “\”}”);
}

Leave a Reply

Your email address will not be published. Required fields are marked *