Skip to content

Commit cacce1c

Browse files
committed
clarify header:location requirement
1 parent b926869 commit cacce1c

File tree

2 files changed

+169
-92
lines changed

2 files changed

+169
-92
lines changed

articles/cognitive-services/Translator/quickstart-translator.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: translator-text
1010
ms.topic: quickstart
11-
ms.date: 07/28/2022
11+
ms.date: 09/14/2022
1212
ms.author: lajanuar
1313
ms.devlang: csharp, golang, java, javascript, python
1414
---
@@ -24,10 +24,10 @@ In this quickstart, you'll get started using the Translator service to [translat
2424

2525
> [!NOTE]
2626
>
27-
> * For this quickstart it is recommended that you use a Translator text single-service subscription.
28-
> * With the single-service subscription you'll include one authorization header (**Ocp-Apim-Subscription-key**) with the REST API request. The value for Ocp-Apim-Subscription-key is your Azure secret key for your Translator Text subscription.
29-
> * If you choose to use the multi-service Cognitive Services subscription, it requires two authentication headers (**Ocp-Api-Subscription-Key** and **Ocp-Apim-Subscription-Region**). The value for Ocp-Apim-Subscription-Region is the region associated with your subscription.
30-
> * For more information on how to use the Ocp-Apim-Subscription-Region header, _see_ [Use the Text Translator APIs](translator-text-apis.md).
27+
> * For this quickstart it is recommended that you use a Translator text single-service global resource.
28+
> * With a single-service global resource you'll include one authorization header (**Ocp-Apim-Subscription-key**) with the REST API request. The value for Ocp-Apim-Subscription-key is your Azure secret key for your Translator Text subscription.
29+
> * If you choose to use the multi-service Cognitive Services or regional Translator resource, two authentication headers will be required: (**Ocp-Api-Subscription-Key** and **Ocp-Apim-Subscription-Region**). The value for Ocp-Apim-Subscription-Region is the region associated with your subscription.
30+
> * For more information on how to use the **Ocp-Apim-Subscription-Region** header, _see_ [Text Translator REST API headers](translator-text-apis.md).
3131
3232
## Prerequisites
3333

@@ -52,13 +52,12 @@ To call the Translator service via the [REST API](reference/rest-api-guide.md),
5252

5353
For more information on Translator authentication options, _see_ the [Translator v3 reference](./reference/v3-0-reference.md#authentication) guide.
5454

55-
|Header|Value| Condition |
55+
Header|Value| Condition |
5656
|--- |:--- |:---|
57-
|**Ocp-Apim-Subscription-Key** |Your Translator service key from the Azure portal.|<ul><li>***Required***</li></ul> |
58-
|**Content-Type**|The content type of the payload. The accepted value is **application/json** or **charset=UTF-8**.|<ul><li>***Required***</li></ul>|
59-
|**Content-Length**|The **length of the request** body.|<ul><li>***Optional***</li></ul> |
60-
|**X-ClientTraceId**|A client-generated GUID to uniquely identify the request. You can omit this header if you include the trace ID in the query string using a query parameter named ClientTraceId.|<ul><li>***Optional***</li></ul>
61-
|||
57+
|**Ocp-Apim-Subscription-Key** |Your Translator service key from the Azure portal.|&bullet; ***Required***|
58+
|**Ocp-Apim-Subscription-Region**|The region where your resource was created. |&bullet; ***Required*** when using a multi-service Cognitive Services or regional (non-global) resource.</br>&bullet; ***Optional*** when using a single-service global Translator Resource.
59+
|**Content-Type**|The content type of the payload. The accepted value is **application/json** or **charset=UTF-8**.|&bullet; **Required**|
60+
|**Content-Length**|The **length of the request** body.|&bullet; ***Optional***|
6261

6362
> [!IMPORTANT]
6463
>
@@ -135,6 +134,10 @@ class Program
135134
private static readonly string key = "<your-translator-key>";
136135
private static readonly string endpoint = "https://api.cognitive.microsofttranslator.com";
137136

137+
// location, also known as region.
138+
// required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.
139+
private static readonly string location = "<YOUR-RESOURCE-LOCATION>";
140+
138141
static async Task Main(string[] args)
139142
{
140143
// Input and output languages are defined as parameters.
@@ -151,6 +154,8 @@ class Program
151154
request.RequestUri = new Uri(endpoint + route);
152155
request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
153156
request.Headers.Add("Ocp-Apim-Subscription-Key", key);
157+
// location required if you're using a multi-service or regional (not global) resource.
158+
request.Headers.Add("Ocp-Apim-Subscription-Region", location);
154159

155160
// Send the request and get response.
156161
HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
@@ -251,6 +256,10 @@ func main() {
251256
endpoint := "https://api.cognitive.microsofttranslator.com/"
252257
uri := endpoint + "/translate?api-version=3.0"
253258

259+
// location, also known as region.
260+
// required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.
261+
location := "<YOUR-RESOURCE-LOCATION>";
262+
254263
// Build the request URL. See: https://go.dev/pkg/net/url/#example_URL_Parse
255264
u, _ := url.Parse(uri)
256265
q := u.Query()
@@ -274,6 +283,8 @@ func main() {
274283
}
275284
// Add required headers to the request
276285
req.Header.Add("Ocp-Apim-Subscription-Key", key)
286+
// location required if you're using a multi-service or regional (not global) resource.
287+
req.Header.Add("Ocp-Apim-Subscription-Region", location)
277288
req.Header.Add("Content-Type", "application/json")
278289

279290
// Call the Translator API
@@ -433,6 +444,10 @@ import okhttp3.Response;
433444

434445
public class TranslatorText {
435446
private static String key = "<your-translator-key";
447+
448+
// location, also known as region.
449+
// required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.
450+
private static String location = "<YOUR-RESOURCE-LOCATION>";
436451

437452

438453
// Instantiates the OkHttpClient.
@@ -447,6 +462,8 @@ public class TranslatorText {
447462
.url("https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=fr&to=zu")
448463
.post(body)
449464
.addHeader("Ocp-Apim-Subscription-Key", key)
465+
// location required if you're using a multi-service or regional (not global) resource.
466+
.addHeader("Ocp-Apim-Subscription-Region", location)
450467
.addHeader("Content-type", "application/json")
451468
.build();
452469
Response response = client.newCall(request).execute();
@@ -584,12 +601,18 @@ After a successful call, you should see the following response:
584601
let key = "<your-translator-key>";
585602
let endpoint = "https://api.cognitive.microsofttranslator.com";
586603

604+
// location, also known as region.
605+
// required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.
606+
let location = "<YOUR-RESOURCE-LOCATION>";
607+
587608
axios({
588609
baseURL: endpoint,
589610
url: '/translate',
590611
method: 'post',
591612
headers: {
592613
'Ocp-Apim-Subscription-Key': key,
614+
// location required if you're using a multi-service or regional (not global) resource.
615+
'Ocp-Apim-Subscription-Region': location,
593616
'Content-type': 'application/json',
594617
'X-ClientTraceId': uuidv4().toString()
595618
},
@@ -687,9 +710,9 @@ import requests, uuid, json
687710
key = "<your-translator-key>"
688711
endpoint = "https://api.cognitive.microsofttranslator.com"
689712

690-
# Add your location, also known as region. The default is global.
691-
# This is required if using a Cognitive Services resource.
692-
location = "YOUR_RESOURCE_LOCATION"
713+
# location, also known as region.
714+
# required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.
715+
location = "<YOUR-RESOURCE-LOCATION>"
693716

694717
path = '/translate'
695718
constructed_url = endpoint + path
@@ -702,6 +725,8 @@ params = {
702725

703726
headers = {
704727
'Ocp-Apim-Subscription-Key': key,
728+
# location required if you're using a multi-service or regional (not global) resource.
729+
'Ocp-Apim-Subscription-Region': location,
705730
'Content-type': 'application/json',
706731
'X-ClientTraceId': str(uuid.uuid4())
707732
}

0 commit comments

Comments
 (0)