Any tool that allows you to make REST API calls, such as cURL or Postman. The article provides cURL examples.
10 minutes of spare time.
Getting an access token
The GroupDocs.Translation Cloud API is fully compliant with industry security standards and best practices. Data transfer is carried out using JWT authentication, which eliminates all possibilities of data theft or disclosure.
To obtain a JWT token, get the Client ID and Client Secret credentials:
Create the samples storage for exchanging files by clicking the plus icon and following the required steps. Internal storage with 24-hour retention will suffice.
Provide the application name, for example, HelloWorld.
Click Save button.
Click the newly created HelloWorld application and copy the values from Client Id and Client Secret fields.
Now request an access token with the following API call:
The access token will be valid for the number of seconds specified in the expires_in property. If it has expired, request a new one using the same credentials.
Sending text for translation
Let’s translate the following simple text from English to German:
Hello, world! I can read this text in my language.
The translation is carried out in 2 stages. First we need to POST a request to the GroupDocs.Translation Cloud API with parameters in JSON format in the body:
curl --location --request POST 'https://api.groupdocs.cloud/v2.0/translation/text'\
--header 'Content-Type: application/json'\
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...J5xlBi7mQfuNMzxpjUGVCUOOuGEd6iuJCbMaGanlhA9g'\
--data '{
"sourceLanguage": "en",
"targetLanguages": [
"de"
],
"texts": [
"Hello, world! I can read this text in my language."
]
}'
The authorization header must contain the access token obtained earlier.
Wait a moment. The request will be placed in the queue and you will get its unique identifier. For example:
The translation will take a second or two, depending on the length of the text and the current GroupDocs.Translation Cloud load. After the translation is completed, the translated text can be obtained by sending the unique identifier of the request obtained on the previous step to https://api.groupdocs.cloud/v2.0/translation/text/ endpoint: