Recently I am setting up some Azure API management services and thinking about how to automate the process of backing up and restoring API management configurations in case of disaster recovery scenarios.

I understand there are many ways to do that. I will start with a C# app first and show you how I achieved to back up the Azure API management service’s configurations to a blob storage via API calls.

Creating Azure AD Application for Token Authentications

  1. Login Azure AD and navigate to the App registrations
  2. Create a new application registration
  3. Fill in the application name and select Native for the application type
  4. Enter a URL for the URL redirection field
  5. Complete the app registration
  6. Go to settings -> Add “Windows Azure Service Management API” as required permissions

Windows Azure Service Management API

Once finish the steps above, you will have Azure App Id & redirect URL, we will use these values to retrieve the authtoken to access azure environment.

I installed  “Microsoft.IdentityModel.Clients.ActiveDirectory” NuGet package in my local visual studio environment and use below code to retrieve the token

var authenticationContext = new AuthenticationContext(“{tenant id}”);

var result = authenticationContext.AcquireToken(“”, {application id}, new Uri({redirect uri});

My local visual studio code looks like below:

Windows Azure Service Management API 1

Once the tenant Id, Application Id, Redirect URL are correctly specified in the , you will get below token result:

Windows Azure Service Management API 2

Calling Azure API to back up or restore API Management service

Back up an API Management Service


Restore an API Management Service


The API request header Content-Type value needs to be set to “application/json”

In the body of request, specify the target Azure Storage account name, access key, blob container name, and backup name


storageAccount : {storage account name for the backup},

accessKey : {access key for the account},

containerName : {backup container name},

backupName : {backup blob name}


Below is the code I created to make the API call to trigger backup.

Windows Azure Service Management API 3

Once the code is successfully run and the backup process is initiated, I receive 202 response code. on the Azure API management service side, I can see my http client retrieves the token and completes the back up from the API management service activity log:

Windows Azure Service Management API 4

If we go to the backup storage location, we will be able to see the successful backup in the target storage container, the storage account can be different regions in order to provide Geo-redundancy.

Windows Azure Service Management API 5

To restore the API service, you can follow the same process of one click re-run the app, retrieve authtokens and call the restore API interface. Once it’s complete the restore, the logs in the API management service will look like below:

Windows Azure Service Management API 6

Hopefully this can be helpful when it comes to API management service. I will try to make the Net code to work on Azure functions next and share with you guys later. 🙂



Join the conversation! 1 Comment

  1. APIM team confirmed they are working on full ARM solution at //build. Think he said they’re targeting Q3


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: