Postman and Azure Translate Text API
Today’s text says how to create a POST method and query an Azure Translate Text API. We are going to detect a language and translate a sentence.
This is an introduction to an article about creating a custom Power Platform connector. Otherwise, you can take advantage of this text ant treat it as a separate topic if you aren’t interested in the mentioned subject. Available 21.06.2024. Here is the link: Power Platform custom connector
Create a Translator service is the first thing to do.
Before we switch over to POSTMAN, we need to gather three pieces of information from the portal:
- a location, “West Europe” as “westeurope” in this case, selected on the screen above and below,
- an API access key, the screen below,
- an endpoint, https://api.cognitive.microsofttranslator.com/
Let’s switch to POSTMAN. Where we detect and translate an exemplary text.
Select a POST method (an orange box) then set an endpoint address (a blue box). In order to detect a language, we need to use a detect method (a green box). In a Params tab, we specify an api-version parameter (a yellow box). Here is the full address: https://api.cognitive.microsofttranslator.com/detect?api-version=3.0
Go to a Headers tab. Where we add three parameters:
- Ocp-Apim-Subscription-Region: westeurope,
- Content-Type: application/json,
- Ocp-Apim-Subscription-Key: a key collected from an Azure portal.
In the last step we specify a request body in a Body tab. In this case it is JSON data.
[
{
"Text":
"A sentence that language is supposed to be detected."
}
]
When you send the request you get a response:
In order to translate a sentence, we can use the previous example with some adjustments:
- replace the detect method to a translate method,
- add a “to” parameter, in this case we translate to a Polish language.
A request body is similar to the previous example.
[
{
"Text":
"This is a sentence that is translated into a Polish language."
}
]
And here is a response.
As I mentioned at the beginning of this article. This is an introduction to the next article about a Power Platform custom connector.
Here is the link: Power Platform custom connector