Introduction

Before using the Agora RESTful API, you need to pass the basic HTTP authentication. This page shows you how to generate a Base64-encoded credential with the Customer ID and Customer Secret provided by Agora, and pass the credential to the Authorization parameter in the request header.

Implementation

  1. Log in to Agora Console, click the account name on the top right of Agora Console, and click RESTful API from the drop-down list to enter the RESTful page.

  2. Click Download to get the Customer ID and Customer Secret.

    The customer ID and customer secret are used for RESTful API access only. You can download the customer secret from Agora Console only once. After downloading the customer secret, keep the customer secret in a safe place.
  3. Fill in the customer ID (customerId) and customer secret (customerSecret) in the following sample code to generate a Base64-encoded credential, and pass the Base64-encoded credential to the Authorization parameter in the HTTP request header.

    Implement HTTP basic authentication on the server, otherwise, you may encounter the risk of data leakage.
    • PHP

      // Generate the base64Credentials (a Base64-encoded credential) with the customer ID (`customerId`) and customer secret (`customerSecret`).
      $base64Credentials = base64_encode("customerId:customerSecret");
      // Pass the base64Credentials to the `Authorization` parameter in the HTTP request header.
      $arr_header = "Authorization: Basic " . $base64Credentials;
    • Java

      // Fill in the customer ID (`customerId`) and customer secret (`customerSecret`) to obtain the plainCredentials.
      String plainCredentials = "customerId:customerSecret";
      // Fill in the plainCredentials to obtain the base64Credentials (a Base64-encoded credential).
      String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes()));
      
      Request request = new Request.Builder()
      ...
      // Pass the base64Credentials to the `Authorization` parameter in the HTTP request header.
      .addHeader("Authorization", "Basic " + base64Credentials)
      ...
    • Swift

      // Fill in the customer ID (`customerId`) and customer secret (`customerSecret`) to obtain the loginString.
      let username = "customerId"
      let password = "customerCertificate"
      let loginString = String(format: "%@:%@", username, password)
      // Fill in the loginString to obtain the loginData.
      let loginData = loginString.data(using: String.Encoding.utf8)!
      // Fill in the loginData to obtain the base64Credentials (a Base64-encoded credential).
      let base64Credentials = loginData.base64EncodedString()
      
      ...
      // Pass the base64Credentials to the `Authorization` parameter in the HTTP request header.
      let headers = ["Authorization", "Basic " + base64LoginString]
      ...
  4. After a successful authentication, you can use the Agora RESTful API as follows: