How to make proper Curl call to Translate API

Mr. Banana 25 Reputation points
2023-07-20T02:50:12.7633333+00:00

Hello,

I am new at this and I apologize for what is likely a simple problem. I simply want to call the translate API and have it return the Spanish version of the English text I pass to it.

I have tried a couple variations of the curl call, and both return errors. The first tells me

  parse error near `&'

And the second tells me:

 URL using bad/illegal format or missing URL

Other than replace the actual key with <text-string>, I have pasted the curl exactly as entered:

curl -v -X POST “https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=es" \     
    -H "Ocp-Apim-ResourceId: MrBanana" \
     -H "Ocp-Apim-Subscription-Region: West US 3" \
     -H "Ocp-Apim-Subscription-Key: <text-string>"
     -H "Content-Type: application/json; charset=UTF-8"
     -data-raw "[{'Text':'Hello friend.'}]"
curl -v -X POST “https://api.cognitive.microsofttranslator.com/translate" -d "api-version=3.0" -d "from=en" -d "to=es" \
    -H "Ocp-Apim-ResourceId: MrBanana" \
     -H "Ocp-Apim-Subscription-Region: West US 3" \
     -H "Ocp-Apim-Subscription-Key: <text-string>"
     -H "Content-Type: application/json; charset=UTF-8"
     -data-raw "[{'Text':'Hello friend.'}]"
Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
390 questions
0 comments No comments
{count} votes

Accepted answer
  1. romungi-MSFT 45,116 Reputation points Microsoft Employee
    2023-07-20T10:29:06.2066667+00:00

    @Mr. Banana The issue is with the starting double quote in your request. You can try the below curl command on your windows machine, just replace your resource key in the header.

    curl -v -X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: <your_key>" -H "Content-Type: application/json; charset=UTF-8" -d "[{'Text':'Hello friend.'}]"

    Also, you do not need all the headers, see the documentation reference here.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.