Jump to content
psycodad

Microsoft Translator Text API v3.0

Recommended Posts

Hello,

I have to migrate to new microsoft translation api. I try to translate the text with the new RestDebugger. It seems to be easy reading the

https://docs.microsoft.com/en-us/azure/cognitive-services/translator/reference/v3-0-translate?tabs=curl

I set all the RestDebugger properties i need but all i get is a "400:BadRequest", "One of the request inputs is not valid".

In the pics attached you can see how i configure the RestDebugger. I downloaded a c# demo project from https://github.com/MicrosoftTranslator/Text-Translation-API-V3-C-Sharp-Tutorial

After setting the COGNITIVE_SERVICES_KEY to my key,

change the url to TEXT_TRANSLATION_API_ENDPOINT = "https://api-eur.cognitive.microsofttranslator.com/{0}?api-version=3.0",

and comment out the two header entries

                //request.Headers.Add("Ocp-Apim-Subscription-Region", "westus");
                //request.Headers.Add("X-ClientTraceId", Guid.NewGuid().ToString());

 

all works well. I assume the problem is in the content body.

 

Can someone point me to the right direction?

 

2019-02-13_09-31-46.png

2019-02-13_09-28-55.png

Share this post


Link to post

I use https://api-eur.cognitive.microsofttranslator.com/translate?api-version=3.0@&from=en&to=de

 

That works well with the c# project with microsoft visual studio. The only difference between your and my URL is that i use the european located server "api-eur." instead of the us "api.".

I think i do something wrong in the RestDebuggers "user defined content".

Calling the "languages" ressources works well. There i do not need a request json content body parameter (see pics).  

2019-02-14_10-51-07.png

2019-02-14_10-50-09.png

Edited by psycodad

Share this post


Link to post

Found the solution:

- Empty TRestRequest.Ressource property

- Remove all parameters except the Header with the subscription key

- Use following BaseURL instead: https://api-eur.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de
 

 

Now all works like expected. But i even do not know why i should not use the TRestRequest.Params and the Ressource property instead of the URL parameters...

  • Thanks 1

Share this post


Link to post

I just wanted to express my thanks for this sample.

 

I tried for days to get this to work with various languages including C# but with no luck at all.

 

Regards

 

-Mohamed

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×