Hello, world!
In this article, you will learn how to translate a simple Microsoft Word document from English to German using GroupDocs.Translation Cloud REST API.
You will need
- Any system with Internet connection.
- Microsoft Word. If you do not have Microsoft Office, you can try a different file format.
- A web browser.
- Any tool that allows you to make REST API calls, such as cURL or Postman. The article provides cURL examples.
- 15 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:
- Sign in to GroupDocs Cloud API Dashboard.
- Go to Applications page.
- Create the
samples
storage for exchanging files by clicking the plus icon and following the required steps. For this example, 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:
curl --location --request POST 'https://api.groupdocs.cloud/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=CLIENT-ID-VALUE' \
--data-urlencode 'client_secret=CLIENT-SECRET-VALUE'
You should get a response that looks something like this:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...Iwr6g2zbFwf1nLtg",
"expires_in": 3600,
"token_type": "Bearer"
}
expires_in
property. If it has expired, request a new one using the same credentials.Preparing a source file
Let’s start with a simple document with minimal formatting:
Save the document as Hello.docx
in your Documents
folder.
Now upload the file to the online storage, created on the previous step:
- Open Files page of GroupDocs Cloud API Dashboard.
- Select
samples
storage. - Drag the
Hello.docx
fromDocuments
folder to the storage.
Translating
Now we are ready for the most intriguing part - the translation. Make the following API call:
curl --location --request POST 'https://api.groupdocs.cloud/v1.0/translation/document' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...Iwr6g2zbFwf1nLtg' \
--data-raw ''\''[{\"format\":\"docx\", \"outformat\":\"docx\", \"pair\":\"en-de\", \"name\":\"Hello.docx\", \"savefile\":\"Hello-DE.docx\", \"storage\":\"samples\"}]'\'''
Read JSON Request Details for more information on the request body parameters.
Wait a few seconds. You will get the following response:
{
"status": "ok",
"message": ".docx file saved successfully, file was fully translated",
"duration": 11.5256778,
"details": null
}
Getting the translated document
- Open Files page of GroupDocs Cloud API Dashboard.
- Select
samples
storage. - Select
Hello-DE.docx
file and click Download in the toolbar.
If you do not see the file, click Refresh in the toolbar. - Open the downloaded document.
What’s next?
Congratulations! You have taken the first step in neural machine translation. Read the Developer’s Guide and API Reference for details on creating advanced translation solutions with GroupDocs.Translation Cloud.