question

Samarth S. avatar image
Samarth S. asked

How to make a http request to a server from alexa skill?

I have been trying to make a http request from the sample colors example code. But I am unable to do so: This is my code: var http = require('http'); var str = ''; var options = { host: ' google.com', port: 80, path: '/' }; var req = http.request(options, function(response) { response.on('data', function (chunk) { str += chunk; }); response.on('end', function () { console.log(req); console.log(str); // your code here if you want to use the results ! }); }).end(); This code works as a sample nodejs file but when used through alexa skill, it doesnt make any http get request. Any help would be appreciated.
alexa skills kitdebugging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ross@Amazon avatar image
Ross@Amazon answered
Please download and check out the sample skills found here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/using-the-alexa-skills-kit-samples. The History Buff and Tide Pooler examples include the code necessary to make HTTP requests.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Antonio Cucciniello avatar image
Antonio Cucciniello answered

I cannot seem to find these examples anymore, would you be able to link them to me @Ross@Amazon?

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-fc42782a-ad6e-4eb8-b9dc-fb840f6726a9 avatar image
newuser-fc42782a-ad6e-4eb8-b9dc-fb840f6726a9 answered

Have you found the samples.

I also cannot found them.

I also cannot make a http request to a server from alexa skill.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

digisam avatar image
digisam answered

Ross's answer was made well over a year ago :) those samples have been retired (i think) but there are lots more, and the new cookbook https://github.com/alexa/alexa-cookbook looks like ti covers things.

Check the https://github.com/alexa/ main repo for other samples.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-fc42782a-ad6e-4eb8-b9dc-fb840f6726a9 avatar image
newuser-fc42782a-ad6e-4eb8-b9dc-fb840f6726a9 answered

Thanks for the links, but i search for .NET Core Lambda Samples for Alexa Skill.

i search for examples with http requests for "GET" and "POST" in .NET

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

IOTwonders avatar image
IOTwonders answered

Hi,

Make sure that you are sending response in 'end' event of http.get. Otherwise your response will be sent to alexa even before the http.get executed fully.

response.on('end', function () {

//Call context.succeed/send response here

});

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-99d040f9-d6c6-404c-b1e7-3a6f88ae97d3 avatar image
newuser-99d040f9-d6c6-404c-b1e7-3a6f88ae97d3 answered

As per the Tide Pooler samples, here I found some bits:

https://github.com/georgechapman/alexa-skills/tree/master/samples/tidePooler

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.