How To Use 
Register an account

Try For Free Now

Dark

Light

Announcement: End of support for old file type in File Translation (08/24)

Announcemnet: System Maintenance (Update: September 17)

Announcement: End of support for old file type in File Translation (08/24)

AUTHENTICATION
JWT Generate
You can generate a JWT for authentication. You can also request for a JWT, please refer to here.

01

/

Generate a JWT.


/**
 * Demo program for generating JWT (JSON Web Token).
 */

const jwt = require('jsonwebtoken');

const TOKEN_SIGNING_OPTIONS = {
  algorithm: 'HS256',
};

const userId = 'MyUserID';
const accessKey = 'my-access-key';
const secretKey = 'my-secret-key';
// seconds
const validDuration = 60 * 30;

const payload = {
  exp: Math.floor(Date.now() / 1000) + validDuration,
  iss: userId,
  accessKey,
};

const encodedJWT = jwt.sign(payload, secretKey, TOKEN_SIGNING_OPTIONS);

console.log(`JWT:${encodedJWT}`);
Currently the Rozetta API only supports token generated with HS256 (HMAC using SHA-256 hash algorithm).

02

/

Send API request with JWT.


/**
 * Demo prorgram of authentication by JWT.
 */

const fetch = require('node-fetch');

const token = 'my-jwt';

const sampleRequest = async () => {
  const url = 'https://translate.rozetta-api.io/api/v1/hello';
  const response = await fetch(url, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${token}`
    }
  });
  const responseJSON = await response.json();
  console.log(responseJSON);
};

sampleRequest();
When sending a request, you should add the `Authorization` header in the request. The value is `Bearer <jwt-token>` where `<jwt-token>` is the JWT you generated above.
The sample above uses `/api/v1/hello` API as an example, other Rozetta APIs also accept authentication using JWT.
©️ 2019 Rozetta API  ・  Powered by Rozetta

Rozetta Corp.

^