Get started with the Microsoft Learn Catalog API using curl and Visual Studio Code

This article will assist you in getting started using the Microsoft Learn Catalog API with curl and Visual Studio Code. If you aren't familiar with the details of the API or the use cases for it, we recommend that you review the Learn Catalog API feature overview article first.

The high-level process we'll walk through is:

  1. Query the Learn Catalog API
  2. Review the initial response
  3. “Prettify” the response
  4. Convert it to a spreadsheet
  5. Try out more queries

Once you start to use the Learn Catalog API for your own needs, you may find yourself modifying these steps slightly, for your desired toolset or needs, but generally the process of using it's the same for all use cases.

Prerequisites

In order to follow the steps in this article, you'll need curl and Visual Studio Code, two popular, free tools for querying APIs.

  • If you already have curl and Visual Studio Code installed, you can skip ahead to the Query the Learn Catalog API section.
  • If you do not have them installed, follow the instructions in the following sections.

Download and setup curl

curl is a popular, free, open-source, command-line tool that can query APIs.

  1. Go to the curl Download Page and download the package applicable for your environment. If you're not sure which one to pick, use the curl Download wizard.
  2. Install the application and follow the prompts to configure. There are no unique settings needed for this article or for querying the Learn Catalog API.

Download and setup Visual Studio Code

Visual Studio Code is a free, powerful code editor created by Microsoft.

  1. Go the Visual Studio Code site and download the package applicable for your environment.
  2. Install the application and follow the prompts to configure.

Query the Learn Catalog API

Because there's no authentication required to use the Learn Catalog API, you can query the API endpoint from any command line that is curl-enabled. For this exercise, we'll use the terminal within Visual Studio Code.

  1. Open Visual Studio Code.
  2. Select Terminal in the top navigation.
  3. Select New Terminal to open a new command terminal.
  4. Pick your terminal of choice (Bash, CMD, etc.) and type the command below. The command below indicates that it wants to use curl, call the unfiltered Learn Catalog API endpoint, and will output the response to a file called “output.json”, in the location defined in the filepath shown in the terminal (ex: C:\Users\<username>):
curl https://learn.microsoft.com/api/catalog >> output.json
  1. If the request was successful, you should see information about the total size of the file, such as 13.1 M (the size is subject to change, depending on the size of the response). If it was unsuccessful, you should receive an error.

Note

You should delete the output.json file after you are done using it, or rename it to be more applicable. If you query the API again using the same file name, it will append the response within the existing file. Another option is to name the file more uniquely during the initial query command such as “output-1212.json” or “output-de-de-2022-12-12.json”.

Review the initial response

The initial response is in JSON and will be “minimized”, meaning that certain spaces, lines, and tabs are removed to make the file smaller.

  1. In Visual Studio Code, select File.
  2. Select Open File.
  3. Navigate to the “output.json” file that was created as part of the previous section.

This minimization is a standard practice and the file can be “prettified” to be more readable by a command in Visual Studio Code, which we’ll do in the next section.

Prettify the response

  1. With the “output.json” file open in Visual Studio Code, use Ctrl+Shift+I.

The JSON should update to split out into multiple lines and be in a more readable format. For information about the different properties and values within the response, view the Learn Catalog API Developer reference article for the data dictionary.

Convert the response to a spreadsheet

There are many people who use the Learn Catalog API for individual tasks or review, as opposed to integrating it into a system. For these use cases, it may be helpful to convert the JSON response into a CSV or Excel format to view as a spreadsheet. You can use any preferred conversion tool, but here we can use the Flatfile Json to CSV converter.

  1. Go to: https://csvjson.com/json2csv.
  2. Upload your output file.
  3. Select Convert.
  4. Select Download.

Note

Be very careful using external online tools to convert data and consider what data you are putting into them. In the case of the Learn Catalog API, the response is publicly available and does not require authentication, so it is ok to use an online tool to help convert the format.

Try out more queries

Follow the steps above to try more queries, such as the ones listed below. View how the response file size changes for each, and the difference in objects within.

Description Query
All items in the Learn Catalog API https://learn.microsoft.com/api/catalog/
All Spanish modules https://learn.microsoft.com/api/catalog/?locale=es-es&type=modules
All modules with a popularity score of 0.9 or higher https://learn.microsoft.com/api/catalog/?type=modules&popularity>0.9
All beginner security training and certification objects https://learn.microsoft.com/api/catalog/?level=beginner&subject=security
All advanced accessibility modules with a popularity score over 0.5 and updated in the last month https://learn.microsoft.com/api/catalog/?level=advanced&subject=accessibility&popularity>0.5&last_modified=gte 2022-10-01

Next steps

We recommend reviewing the resources below to help you on your development journey: