AzureTranslator HTTP Request return The body of the request is not valid JSON

ReMiKU 6 Reputation points
2022-01-26T14:10:09.9+00:00

Hello I'm new to MS Azure and have been trying to use the translator resource with n8n

Using the HTTP Request node I've been trying out all settings available but I don't think the settings or parameters are wrong since I tried posting a request to webhook.site and all the parameters passed successfully

168720-screenshot-2022-01-26-215356.png

But when I try it on the azure API it failed

168771-screenshot-2022-01-26-215558.png

I'm not sure if this is a correct method but I also tried to use Azure Active Directory? To then use the resource by connecting the account? but that aswell gave me an error using n8n OAuth2

168733-screenshot-2022-01-26-220026.png

I've been stuck for days on this issue and I've scoured through forums but to no avail, please help :'( thanks in advance!

Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
343 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. YutongTie-MSFT 46,986 Reputation points
    2022-01-26T19:29:25.733+00:00

    @ReMiKU

    Thanks for reaching out to us here. Seems like the way you are passing your request is not correct, please check below code sample which I just tested and worked.

     import requests, uuid, json  
          
     # Add your subscription key and endpoint  
     subscription_key = "replace_your_key"  
     endpoint = "https://api.cognitive.microsofttranslator.com"  
          
     # Add your location, also known as region. The default is global.  
     # This is required if using a Cognitive Services resource.  
     location = "global"  
          
     path = '/translate'  
     constructed_url = endpoint + path  
          
     params = {  
         'api-version': '3.0',  
         'from': 'en',  
         'to': ['de', 'it']  
     }  
     constructed_url = endpoint + path  
          
     headers = {  
         'Ocp-Apim-Subscription-Key': subscription_key,  
         'Ocp-Apim-Subscription-Region': location,  
         'Content-type': 'application/json',  
         'X-ClientTraceId': str(uuid.uuid4())  
     }  
          
     # You can pass more than one object in body.  
     body = [{  
         'text': 'Hello World!'  
     }]  
          
     request = requests.post(constructed_url, params=params, headers=headers, json=body)  
     response = request.json()  
          
     print(json.dumps(response, sort_keys=True, ensure_ascii=False, indent=4, separators=(',', ': ')))  
    

    Hope this helps.

    Regards,
    Yutong


  2. ReMiKU 6 Reputation points
    2022-02-09T01:41:09.353+00:00

    With the help of MutedJam over on n8n community the problem has been solved
    https://community.n8n.io/t/azuretranslator-http-request-return-the-body-of-the-request-is-not-valid-json/11200

    0 comments No comments