Connect to Media Services v3 API - Java

This article shows you how to connect to the Azure Media Services v3 Java SDK using the service principal sign in method.

In this article, the Visual Studio Code is used to develop the sample app.


  • Follow Writing Java with Visual Studio Code to install:

    • JDK
    • Apache Maven
    • Java Extension Pack
  • Make sure to set JAVA_HOME and PATH environment variables.

  • Create a Media Services account. Be sure to remember the resource group name and the Media Services account name.

  • Follow the steps in the Access APIs topic. Record the subscription ID, application ID (client ID), the authentication key (secret), and the tenant ID that you need in a later step.

Also review:

Create a Maven project

Open a command-line tool and cd to a directory where you want to create the project.

mvn archetype:generate -DartifactId=testAzureApp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

When you run the command, the pom.xml,, and other files are created.

Add dependencies

  1. In Visual Studio Code, open the folder where your project is

  2. Find and open the pom.xml

  3. Add the needed dependencies


Connect to the Java client

  1. Open the file under src\main\java\com\azure\ams and make sure your package is included at the top:

  2. Under the package statement, add these import statements:

  3. To create the Active Directory credentials that you need to make requests, add following code to the main method of the App class and set the values that you got from Access APIs:

    final String clientId = "00000000-0000-0000-0000-000000000000";
    final String tenantId = "00000000-0000-0000-0000-000000000000";
    final String clientSecret = "00000000-0000-0000-0000-000000000000";
    final String subscriptionId = "00000000-0000-0000-0000-000000000000";
    try {
       ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(clientId, tenantId, clientSecret, AzureEnvironment.AZURE);
       MediaManager manager = MediaManager
               .authenticate(credentials, credentials.defaultSubscriptionId());
       System.out.println("signed in");
    catch (Exception e) {
       System.out.println("Exception encountered.");
  4. Run the app.

See also

Next steps

You can now include import*; and start manipulating entities.