Tuesday, April 25, 2023

How to Call Cognitive Service Translator API With Postman

This blog explains how to setup postman to test cognitive service translator. 

Pre-requisites: Cognitive service translator, access to postman

Open postman, add a new post request and add following configurations.

If the translator access limited to VNet use following URL format.

URL : https://your-translate-service-name.cognitiveservices.azure.com/translator/text/v3.0/translate?to=fr

ex: https://my-demo-translator.cognitiveservices.azure.com/translator/text/v3.0/translate?from=en&to=fr



If the translator access enabled from any network, use following URL format.

URL : https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=fr&to=zu



With either of the formats above we need to use body of the request to pass the text we need to translate as shown below.

Body : [{"Text":"Hello, This is translator service"}]

We need to use following values as Headers for either of the request URLs. 


Key

Value

Ocp-Apim-Subscription-Key

Go to Keys and Endpoints of translator. Copy one of the Key values.

Content-Type

 application/json

Ocp-Apim-Subscription-Region

If the translator created with region, Go to Keys and Endpoints of translator service, get the region

Following image shows where to find keys and region from translator service


1 - Get value of one of the Keys as Ocp-Apim-Subscription-Key

2 - Region value as Ocp-Apim-Subscription-Region




No comments:

Post a Comment