Views:

Overview

This is the second part of a two part series. Please see here if you have not completed the setup guide yet. 

Now that the Active Directory Security has been set up on Azure functions, this article will show how to execute Azure functions via North52. 

First, we will setup the xCache records where we will store our unique parameters and secrets. 

Second, we will create the formula that uses these xCache records and calls the Azure function from the setup article. 

Third, we will then test this formula. 

Create xCache records

  • Go to Settings > N52 Formula
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_DirectoryID
    • Scroll down and in Value (Secured), enter your Directory ID
      • In this example, we will paste the Directory ID we copied from the setup article
  • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_Resource
    • Scroll down and in Value (Secured), enter your Resource 
      • In this example, we will paste the Resource we copied from the setup article
    • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_ClientID
    • Scroll down and in Value (Secured), enter your Client ID
      • In this example, we will paste the Client ID we copied from the setup article
    • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_ClientSecret
    • Scroll down and in Value (Secured), enter your Client Secret
      • In this example, we will paste the Client Secret we copied from the setup article
    • Change the DataType to String (Password)
    • Click Save
  • Click New
    • For Category, enter AzureFunctions
    • For Base Key, enter AzureFunctions_FunctionURL
    • Scroll down and in Value (Secured), enter your Function URL
      • In this example, we will paste the Function URL we copied from the setup article
    • Click Save

Create N52 Formula

  • Go to Settings > N52 Formula
  • Click New
  • Set Formula type to Clientside - Calculation
  • Select Editor to be Classic
  • Leave Entity as Account
  • Click Create
  • Give it the name Azure Functions with Active Directory Security 
  • Copy and paste the formula below:
    Smartflow(
      SetVar('token',
        azureadgettoken(xCacheGetGlobal('AzureFunctions_DirectoryID'), 
          SetRequestParams(
            'resource', xCacheGetGlobal('AzureFunctions_Resource'), 
            'client_id', xCacheGetGlobal('AzureFunctions_ClientID'),
            'client_secret', xCacheGetGlobal('AzureFunctions_ClientSecret'),
            'grant_type', 'client_credentials'))),
    
      CallRestAPI( 
        SetRequestBaseURL(xCacheGetGlobal('AzureFunctions_FunctionURL')),
        SetRequestResource(''),
        SetRequestDetails('GET'),
        SetRequestHeaders('Authorization', 'Bearer ' + GetVar('token'), 'Content-Type', 'application/json; charset=utf-8', 'Accept', 'application/json'),
        SetRequestParams('name', 'Bill Gates'),
        SetRequestAuthenticationNone(),
        SetRequestFiles(), 
        SetRequestExpected('OK'),  
        SetRequestActionPass(getvar('responsecontent')),
        SetRequestActionFail(getvar('responsecontent'))))
    
  • Click Save

Test

  • Click on the lightning bolt button in the top right of the formula editor
  • Click Execute
  • You will see the result appear: