Ytel API

Successfully add SMS and voice capabilities into your application without any telecommunications experience

API Reference    Documentation

OTP API Usage

How to Use Our One Time Password Application

Getting Started

In order to use the app, please provide your Ytel account’s username, password, and phone number. If you do not know or have a Ytel accountId, please contact our customer service or sign-up for one. Once you provide the needed information, we will take care of the rest on our end.

Authentication Token

First, the application will look at the user’s credential (i.e. the username and password) in order to access the first endpoint. The first endpoint creates the authorization token that will qualify the user to access an OTP (one time password). Our validation token is created through our authentication token service. To learn more about our post-request service, documentation can be found by viewing our Authentication Overview .


public class GetYtelAuthorizationToken {

  public static AuthTokenResponse getToken(String username, String password) throws IOException {

    URL url = new URL("https://api-beta.ytel.com/auth/v2/token/");
    HttpURLConnection postConnection = (HttpURLConnection) url.openConnection();

    postConnection.setRequestMethod("POST");
    postConnection.setRequestProperty("accept", "application/json");
    postConnection.setRequestProperty("Content-Type", "application/json");

    postConnection.setDoOutput(true);

    AuthTokenRequest request = new AuthTokenRequest(username, password);

    Gson gson = new GsonBuilder().create();
    String getToken = gson.toJson(request).toString();

    try (OutputStream os = postConnection.getOutputStream()) {
      byte[] input = getToken.getBytes("utf-8");
      os.write(input, 0, input.length);
    }
    int responseCode = postConnection.getResponseCode();

    if ((responseCode == HttpURLConnection.HTTP_CREATED) || (responseCode == HttpURLConnection.HTTP_OK)) {
      BufferedReader in = new BufferedReader(
          new InputStreamReader(postConnection.getInputStream(), "utf-8"));
      StringBuilder content = new StringBuilder();
      String inputLine = null;

      while (null != (inputLine = in.readLine())) {
        content.append(inputLine.trim());
      }
      in.close();
      JsonObject jsonObject = new JsonParser().parse(content.toString()).getAsJsonObject();
      AuthTokenResponse authToken = gson.fromJson(jsonObject, AuthTokenResponse.class);
      postConnection.disconnect();
      return authToken;
    } else {
      return null;
    }
  }
}

OTP Endpoint

Once the authorization is created, it will reach our unique OTP endpoint. The endpoint will analyze if the authorization token is verified and if the phone number is wireless. If both passed, the application will send a text message with the one time password. Documentation can be found in our OTP API Reference.

public class YtelApi {
  @SuppressWarnings("serial")
  private static class WrappedYtelOtpResponse extends ResponseWrapper<YtelOtpResponse> {
  }

  public static YtelOtpResponse sendOtp(String toNumber, String accessToken) throws IOException {

    URL url = new URL("https://api-beta.ytel.com/api/v4/sms/otp");
    HttpURLConnection postConnection = (HttpURLConnection) url.openConnection();

    postConnection.setRequestMethod("POST");
    postConnection.setRequestProperty("accept", "application/json");
    postConnection.setRequestProperty("Content-Type", "application/json");
    postConnection.setRequestProperty("Authorization", "Bearer " + accessToken);

    postConnection.setDoOutput(true);

    OtpRequest request = new OtpRequest(toNumber);

    Gson gson = new GsonBuilder().create();
    String getToken = gson.toJson(request).toString();

    try (OutputStream os = postConnection.getOutputStream()) {
      byte[] input = getToken.getBytes("utf-8");
      os.write(input, 0, input.length);
    }
    int responseCode = postConnection.getResponseCode();

    if ((responseCode == HttpURLConnection.HTTP_CREATED) || (responseCode == HttpURLConnection.HTTP_OK)) {
      BufferedReader in = new BufferedReader(new InputStreamReader(postConnection.getInputStream(), "utf-8"));
      StringBuilder content = new StringBuilder();
      String inputLine = null;
      while (null != (inputLine = in.readLine())) {
        content.append(inputLine.trim());
      }
      in.close();
      YtelOtpResponse otpResponse = gson.fromJson(content.toString(), YtelOtpResponse.class);
      postConnection.disconnect();
      return otpResponse;
    } else {
      postConnection.getErrorStream();
      return null;
    }

  }

}

Try Out Our Code Yourself!

Below is our link to our Github to install to OTP application! To learn more about how to run the code on your own computer, check out the readme on the Github page.


OTP API Usage


How to Use Our One Time Password Application

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.