Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translator API always gives me 404 #57430

Closed
tinytortoise-dev opened this issue Jun 19, 2020 · 8 comments
Closed

Translator API always gives me 404 #57430

tinytortoise-dev opened this issue Jun 19, 2020 · 8 comments

Comments

@tinytortoise-dev
Copy link

tinytortoise-dev commented Jun 19, 2020

I'm trying to use translator API through a free trial subscription. After creating it, I set resource groups and add cognitive service to it. On that cognitive service page, I followed the "Quick Start" guide and got a pair of keys and ENDPOINT url.

Then I followed this document. It says an API key and endpoint are needed to use translator API. And I get them from RESOURCE MANAGEMENT>Keys and Endpoint.
https://docs.microsoft.com/en-gb/azure/cognitive-services/translator/quickstart-translate?pivots=programming-language-javascript

But I always get 404 status code from this API every time I send a request. Is there anything I do wrong? How can I use this API?

SubscriptionID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzz
My code:

 const subscriptionKey = 'my-sub-key'; // There are two keys, key1 and key2. I use key1 here.
 const endpoint = 'https://japaneast.api.cognitive.microsoft.com/';
 const options = {
        method: 'POST',
        baseUrl: endpoint,
        url: 'translate',
        qs: {
          'api-version': '3.0',
          'to': 'en'
        },
        headers: {
          'Ocp-Apim-Subscription-Key': subscriptionKey,
          'Content-type': 'application/json',
          'X-ClientTraceId': uuidv4().toString()
        },
        body: [{
          'text': 'hello world'
        }],
        json: true,
 };
 request(options, function (err, resFromMicrosoft, body) {
        res.json(resFromMicrosoft);
}

Error response:

{
        "statusCode": 404,
        "body": {
            "error": {
                "code": "404",
                "message": "Resource not found"
            }
        },
        "headers": {
            "content-length": "56",
            "content-type": "application/json",
            "apim-request-id": "e2ae69cc-b93c-4db2-aef4-47096eb3ec61",
            "strict-transport-security": "max-age=31536000; includeSubDomains; preload",
            "x-content-type-options": "nosniff",
            "date": "Fri, 19 Jun 2020 06:11:24 GMT",
            "connection": "close"
        },
        "request": {
            "uri": {
                "protocol": "https:",
                "slashes": true,
                "auth": null,
                "host": "japaneast.api.cognitive.microsoft.com",
                "port": null,
                "hostname": "japaneast.api.cognitive.microsoft.com",
                "hash": null,
                "search": "?api-version=3.0&to=en",
                "query": "api-version=3.0&to=en",
                "pathname": "/translate",
                "path": "/translate?api-version=3.0&to=en",
                "href": "https://japaneast.api.cognitive.microsoft.com/translate?api-version=3.0&to=en"
            },
            "method": "POST",
            "headers": {
                "Ocp-Apim-Subscription-Key": "my-sub-key",
                "Content-type": "application/json",
                "X-ClientTraceId": "8eedf6f4-db0c-45cb-a95b-92a2797df067",
                "accept": "application/json",
                "content-length": 83
            }
        }
    }

Document details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@SnehaAgrawal-MSFT
Copy link
Contributor

@tinytortoise-dev Thanks for the feedback! We are currently investigating and will update you shortly.

@RohitMungi-MSFT
Copy link
Contributor

@tinytortoise-dev If you have already created a new resource from azure portal you can use the endpoint name that is available on the resource page directly. For example:

image

You can also use it as mentioned in the document.

image

@manikyabard
Copy link

Try using the global endpoint in your code instead of the one given in "APIs and Endpoints".
So in this case, put https://api.cognitive.microsofttranslator.com as your endpoint.

@tinytortoise-dev
Copy link
Author

@RohitMungi-MSFT @manikyabard I've already tried using the global endpoint. But got a bit different response:

{
        "statusCode": 401,
        "body": {
            "error": {
                "code": 401000,
                "message": "The request is not authorized because credentials are missing or invalid."
            }
        },
        "headers": {
            "content-type": "text/plain; charset=utf-8",
            "x-requestid": "TRAN.PS1P.8BE7.0622T1018.4F006B",
            "access-control-expose-headers": "X-RequestId",
            "x-content-type-options": "nosniff",
            "strict-transport-security": "max-age=31536000; includeSubDomains",
            "date": "Mon, 22 Jun 2020 10:18:10 GMT",
            "connection": "close",
            "content-length": "111"
        },
        "request": {
            "uri": {
                "protocol": "https:",
                "slashes": true,
                "auth": null,
                "host": "api.cognitive.microsofttranslator.com",
                "port": null,
                "hostname": "api.cognitive.microsofttranslator.com",
                "hash": null,
                "search": "?api-version=3.0&to%5B0%5D=en",
                "query": "api-version=3.0&to%5B0%5D=en",
                "pathname": "/translate",
                "path": "/translate?api-version=3.0&to%5B0%5D=en",
                "href": "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to%5B0%5D=en"
            },
            "method": "POST",
            "headers": {
                "Ocp-Apim-Subscription-Key": "my-sub-key",
                "Content-type": "application/json",
                "X-ClientTraceId": "7cedbf92-407f-45e6-9c93-be338bd6794a",
                "accept": "application/json",
                "content-length": 83
            }
        }
 }

And I want to make sure what subscription key is.
sub1
sub2

I suppose KEY1 and KEY2 are the subscription keys, right?

Here are the failed combinations:
My ENDPOINT & KEY1(404)
My ENDPOINT & KEY2(404)
Global Endpoint & KEY1(401)
Global Endpoint & KEY2(401)

@RohitMungi-MSFT
Copy link
Contributor

@tinytortoise-dev It looks like you are using a common cognitive service resource and a key. Most the services have moved to using an individual resource type and if you can create and use the translator resource the steps mentioned in the documentation should work as is.

image

@tinytortoise-dev
Copy link
Author

@RohitMungi-MSFT Would you share the exact document which mentions about the difference between a common cognitive service and an individual resource type, and the reason why a user cannot use translator API through the common congnitive service, if you don't mind. It would be also highly appreciated if you tell me how to create an individual resource because I'm not a master yoda of Azure services.

@RohitMungi-MSFT
Copy link
Contributor

Sure, a common resource is used to consolidate the billing. Here are some details about single and multi service resources.

This documentation or quickstart uses a single resource so the steps mentioned are using those endpoints.

@RohitMungi-MSFT
Copy link
Contributor

@tinytortoise-dev We hope you are able to proceed further using the translator resource with the correct endpoint. You can also refer the API reference for more help. If there are no further questions regarding this matter, we will go ahead and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
@PRMerger8 @PRMerger13 @manikyabard @SnehaAgrawal-MSFT @RohitMungi-MSFT @tinytortoise-dev and others