Reputation: 405
I am trying to call the below function is dialogflow but I am unable to response body
function calltransliterate(agent) {
console.log('calltransliterate');
return new Promise((resolve, reject) => {
const trnstext= agent.parameters.trnsvar;
var trnsaltedtext =null;
var key_var = '**API_KEY**';
var subscriptionKey = key_var;
var endpoint_var = 'https://api.cognitive.microsofttranslator.com/';
var endpoint = endpoint_var;
let options = {
method: 'POST',
baseUrl: endpoint,
url: 'transliterate',
qs: {
'api-version': '3.0',
'language': 'ja',
'fromScript': 'jpan',
'toScript': 'latn'
},
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
},
body: [{
'text': trnstext
}],
json: true,
};
console.log('before request');
requestModule.get(options, (error, response, body) =>{
console.log('after request');
console.log( (body)); //error occures here
});
});
}
but console.log( (body)); message: 'The request method is not supported for the requested resource.'
Upvotes: 0
Views: 17
Reputation: 50701
Although you are setting options.method
to "POST", you're then calling requestModule.get()
, which would change the method to "GET".
Try something more like
requestModule.post( options, (error, response, body) => {
//...
});
Upvotes: 1