Understanding API Management Source Code

Developing in Azure API Management is done inside the Azure portal or in the Publisher Portal that comes with the API Management instance, developing and testing is easy, but when it comes to move the developed API to the next instance (Test or Prod) it becomes tricky.

In this demo instance I have 2 API’s and logic applied to handle authentication and formatting.

Where is the code?

When developing API’s in API Management publisher portal you quickly learn that API signature and policy codes are separated and handled in different areas of the portal, API and Policy. This experience is not as clear in the new API blade inside the Azure Portal where a lot of work has been done to make it easier to understand the API’s and see the whole picture at one place.

But the difference is quite important, the API is the “external” definition needed by clients to understand and implement our API and the Policy part is logic that is executed when a call is made to the API.

Exporting the API; Press export and select “OpenAPI specification”

Inspecting the file shows that only the swagger definition is exported and not the logic added to the

We now test to extract the code using the GIT option, in the publisher portal under “Security” -> “Configuration repository”

First Press the “Save configuration to repository”, note that after the save is completed the Git icon on the top right corner changes color to green.

Get the clone URL and note that the Username is “apim”, scroll down and generate a password

Now use the credentials and password to connect. Tip:_ if you are using PowerShell or another tool that requires the authentication in the form, remember to URL encode the password:_

_git clone _https://{user}:{password}@ibizmalo.scm.azure-api.net

Inspecting the content: (2 folders down) and we find the source code!

All of these we can copy to the next instance, but! There are some things to take into consideration; each group/product etc. has a unique ID (if these are manually created in the instances it’s not guaranteed to be the same and the import won’t work in another instance, so import everything you need)

Import changes into a API Management instance

The next step is to import these files to another API Management instance, so to get started, we need to clone the code from this API Management instance:

Copy the files and commit, after that we need to deploy the changes in the repository to the API Management instance and once again we need to go to the “publisher” portal and “Security” -> “Configuration repository”. Scroll down and press the “Deploy repository configuration” and the changes are applied.

Posted in: •Azure API Management  •Integration  | Tagged: •API  •API Management  •Azure