Office 365 Tech

How to Build a Microsoft Flow Custom Connector to Spanning API

How to Build a Microsoft Flow Custom Connector to Spanning API

Since becoming a member of the workforce at Spanning, I’ve had the pleasure of serving to clients craft options utilizing the Spanning Backup for Workplace 365 API. We’ve a extremely popular PowerShell module and I’ve been demonstrating methods to use the module in PowerShell scripts to automate the license software for customers.

Lately, I used to be requested if we might use Microsoft Move to do the identical factor. It seems which you can and it’s straightforward! Microsoft Movement offers a function referred to as a Customized Connectors that empower you to craft your personal options with REST API endpoints just like the Spanning Backup for Workplace 365 API.

Why Construct a Movement Customized Connector?

Spanning Backup for Workplace 365 offers many nice options by means of the Tenant Portal or with the API wen utilizing our PowerShell module. Nonetheless, there could also be different use instances an organization may need to discover, like enabling a Spanning Consumer License when a consumer is added to a Azure AD Safety Group. A Microsoft Movement Customized Connector could make this attainable. You can additionally run a scheduled Circulate to find out when you’re approaching your license restrict to remind you so as to add further licenses. Any question you can also make of our API is feasible from Movement with a Customized Connector.

Overview

To create a Movement Customized Connector, it’s worthwhile to first generate a API Key on your Spanning Tenant. Then you’ll use that key to permit Microsoft Stream to make requests of your tenant. On this submit I’ll present you a easy circulate that you possibly can create to license a single consumer. Within the video that accompanies this submit I’ll present you the way to monitor an Azure AD Group and license the customers which are added.

Generate the Spanning API Token

Step 1) Navigate to your Spanning Backup for Workplace 365 Portal.
Step 2) Select Settings and scroll right down to the API Token Click on Generate Token.

Step three) The brand new API Token shall be displayed. Be sure you copy it and reserve it someplace protected. This key permits entry to your Spanning Tenant, so deal with it like a password. Once you navigate away from the web page it should disappear.

Notice: When you solely see the Revoke Token button, another person generated the Token already. For those who can’t get the present token, you have to know who generated the Token, and examine that it’s okay to click on Revoke Token after which generate a brand new token. In fact, this can invalidate the earlier token and you’ll need to replace the places the place it’s getting used.

Use PowerShell to Create an Authentication Header

Step 1) Obtain the Spanning Backup for Workplace 365 PowerShell module.
Step 2) Open PowerShell and import the module.

PS>> Import-Module .SpanningO365

Step three) Get the Spanning authentication token by passing your API Token, Area, and Admin E-mail.

PS >> $api = “8b2bc8a9-2fcb-45d6-9469-4d8e667d84be”
PS >> $admin = “MeganB@M365x186877.OnMicrosoft.com”
PS >> $auth = Get-SpanningAuthentication -ApiToken $api -Area “US” -AdminEmail $admin

Step four) Output the Authorization header and replica it for later use.

$auth.Headers.Authorization

Create a Customized Connector in Microsoft Movement

In a associated publish, Create a Customized Move Connector for the Microsoft Graph, I exhibit how one can use Postman to check your requests earlier than leaping into Microsoft Move. On this publish we’ll begin in Move.

Step 1) Navigate to Microsoft Move.
Step 2) From the “gear” menu, select Customized Connectors.

Step three) On the Customized connectors web page, select the Create customized connector menu and choose Create from clean.
Step four) Give your connector a Identify like Spanning backup API. Click on Proceed.
Step 5) You possibly can provide an icon and background colour, however the essential half right here is to offer the right Host on your area.

a. US – o365-api-us.spanningbackup.com
b. APAC – o365-api-ap.spanningbackup.com
c. EMEA – o365-api-eu.spanningbackup.com

Step 6) Click on Create connector.

Configure Connector Safety

The Spanning API authenticates with an Authorization Token that you simply beforehand generated in PowerShell and saved. On this part you’ll apply that token to the Connector Safety.

Step 1) Click on on the Safety tab.
Step 2) Click on Edit.
Step three) Select API Key for the kind of authentication. The API Key part must be displayed.
Step four) Within the Parameter label subject enter API Token.
Step 5) Within the Parameter identify area enter Authorization.
Step 6) Within the Parameter location subject depart the default Header.

Step 7) Click on Replace connector.

Configure Connector Definition

For this instance, I’d wish to implement two totally different requests, one to get the Tenant info and one other to use a license to a consumer. (The Spanning API is documented right here)

Request 1) Get Tenant Info

Request: GET https://o365-api-Region.spanningbackup.com/tenant
Response:

“licenses”: 100,
“customers”: 106,
“assigned”: 16,
“standing”: “trial”

Request 2) Assign License to Consumer

Request: POST : https://o365-api-Region.spanningbackup.com/user/UserPrincipalName/assign
Response:

“userPrincipalName”: “ruby@doghousetoys.com”,
“licensed”: true

Armed with this info we will create two customized actions to allow automation with Microsoft Movement.

Step 1) Click on on the Definition tab.
Step 2) Underneath Actions, click on New motion. Full the Common part as follows:

a. Abstract: Get Spanning Tenant Information
b. Description: Request Tenant info from Spanning Backup for Workplace 365
c. Operation ID: GetSpanningTenantInfo

Step three) Request, click on Import from pattern.
Step four) Within the Import from pattern blade, select GET and enter the Spanning API URL on your area.

Step 5) Click on Import.
Step 6) Within the Response part, click on Import from pattern.
Step 7) On the Import from pattern blade, paste within the Tenant response from above.

Step eight) Click on Import.
Step 9) Click on Replace connector to save lots of your modifications.

Check the Tenant Information Connection

Step 1) Click on the Check tab.
Step 2) Beneath Connections, click on New connection. You’ll be redirected to a web page to enter your API Token. Paste within the token you beforehand copied and click on Create connection.

Step three) You need to see an alert that you have to replace the connector to check your modifications. Click on Replace connector and if essential click on the Refresh button.

Step four) It is best to have the ability to decide your connection from the record of connections.

Step 5) Click on Replace connector as soon as extra and it is best to see the GetSpanningTenantInfo Operation. Click on Check Operation.
Step 6) You need to get an OK 200 response out of your tenant.

Add Consumer Licensing

Step 1) Click on on the Definition tab.
Step 2) Click on New motion.
Step three) Full the Common part as follows:

a. Abstract: License Spanning Consumer
b. Description: Apply a license to a Spanning Consumer
c. Operation ID: LicenseSpanningUser

Step four) Within the Request part, click on Import from pattern.
Step 5) Select POST and paste within the following request making certain that you simply set the right area.

a. https://o365-api-region.spanningbackup.com/user/UserPrincipalName/assign

Step 6) Depart the opposite fields clean and click on Import.
Step 7) You must see that the UserPrincipalName variable is transformed to a parameter.

Step eight) Within the Response part, click on Add default response. Within the Import from pattern blade, paste within the response physique into the Physique area.

Step 9) Click on Import.
Step 10) Click on Replace connector.
Step 11) Click on on the Check tab and you need to see two operations. Click on LicenseSpanningUser.
Step 12) Provide a legitimate UPN for a consumer and click on Check operation.
Step 13) It is best to get an OK 200 response and see the consumer is licensed.

Step 14) Click on Replace connector. If all your exams labored appropriately, you’re able to create your Stream.

Check the Connector in Stream

At this level you’re prepared to check the Connector. To do that create a brand new Move. I want to start from a guide motion like a button push, however you need to use any set off you want. For this easy state of affairs I’m going to simply accept an e-mail handle for the UPN worth after which license the consumer. Then I’ll ship a delegated administrator an e-mail containing the consumer info and the up to date Tenant info.

Step 1) Click on My Flows.
Step 2) Click on New | Create from clean. Click on Create from clean once more.
Step three) Within the Search connectors and triggers subject sort Button. Choose Move button for cellular.

Step four) Click on Add an enter. Select E-mail sort and alter the label to UPN.
Step 5) Within the Circulate Title subject change the worth to Add a Spanning License. Click on Save.

Step 6) Click on New step. Sort Spanning within the search field.
Step 7) Select the License Spanning Consumer motion.

Step eight) Within the UserPrincipalName subject for the License Spanning Consumer motion add the UPN output from the Manually set off movement set off.

Step 9) Click on New step and seek for Spanning. This time select the Get Spanning Tenant Information motion and add it to the Stream.
Step 10) Click on New step and add a Ship an e-mail motion.
Step 11) Configure the Ship an e-mail motion as follows:

a. To: Specify your e mail handle
b. Topic: New Consumer Assigned Spanning License
c. Physique: Use the next HTML substitute the tokens as indicated.

New License Task

Microsoft Circulate has assigned a brand new Spanning license to the UPN: UPN.

Your tenant configuration it now:

Standing standing
Licenses licenses
Assigned assigned
Customers customers

Have a pleasant day!

Step 12) Click on Present superior choices and alter the Is HTML worth to Sure.

Step 13) Click on Save.

A Remaining Check

Time to check your Movement.

Step 1) Click on Check.
Step 2) On the consent web page click on Proceed.
Step three) On the Run Circulate web page enter the UPN of a consumer you want to license. This area will validate the consumer out of your Workplace 365 Tenant. In my case the dialog hides the consumer lookup, so you could scroll somewhat and choose the consumer. As soon as chosen, they need to seem under the dialog.

Step four) Click on Run move.
Step 5) Click on Executed on the affirmation dialog and look at the outcomes of your check.

Step 6) You need to see that each one steps had run efficiently. Additional, if you open every motion, you must see the values that have been processed with every step.
Step 7) Lastly, open your e-mail and you must see the e-mail affirmation.

Conclusion

Now that you’ve the Spanning API connector configured you’ll be able to add further actions and create extra complicated Flows with the connector. For instance, you can use a Customized connector to watch an Azure AD Group. Then when the group modifications you would act based mostly on these modifications, like including licenses to the customers added to the group. I’ll cowl that within the video under.