article

Amelia@Amazon avatar image
Amelia@Amazon posted

Testing your Alexa Skill with cURL.

Note: You may now wish to use the Skill Management API to test your skills. More information can be found here: https://developer.amazon.com/docs/smapi/skill-testing-operations.html

Issue:

While you can use your Echo device for testing your application, you may wish to test against your service directly, whether for automating your test process or for getting information in a more easily digestible format.

Resolution:

To facilitate this, you can use a command line tool called Curl to make requests against and receive replies to your application service. If you do not already have Curl installed, you can download the latest binaries from http://curl.haxx.se/download.html. Curl is a command-line tool which allows you to send and receive data via multiple protocols, HTTPS in the case of the Echo.

Alternatively you can use the Service Simulator to test your Skill. You can find more information here.

Sample Code

    curl -v -k https://example.com/endpoint --data-binary '{
        "version" : "string",
        "session" : {
            "new" : boolean,
            "sessionId" : "string",
            "attributes" : {
                "string" : object
            },
            "user" : {
                "userId" : "string"
            }
        },
        "request" : object
        }
    }'

Explanation of each part of command (Note: more information in regards to each element of the actual request data can be found in the "Request format" section of the Application Service Interface document)

1. curl: using the curl command to pass the data to the endpoint

2. -v: verbose, gives us more output to debug any issues with the syntax or endpoint

3. -k: allows the use of insecure certificates. If your echo app is using a self-signed certificate which is not installed on the OS, this is required, otherwise you will get a certificate error

4. https://example.com/endpoint: This is the endpoint for your echo application. If you are running your test environment on a non-standard port, you can add a port after a colon at the end of the url, such as http://example.com/endpoint:8888

5. --data-binary: passes the data that follows directly to the endpoint with no pre-processing applied to it

6. version: simply a string that defines the version of the requester, such as "1.0"

7. session: Session object contains the context of the request from the perspective of the client

a. new: true or false, indicates whether this is a new session b. sessionID: Unique identifier per active session c. attributes: map of key value pairs with data to be used by the application d. user: This object gives information about the user making the request

1. userId: Unique ID for the user interacting with the Echo

8. request: An object with more data for the request

Echo application service HTTPS response:

Sample Code

    {
        "version" : "string",
        "response" : {
            "outputSpeech" : {
                "type" : "string",
                "text" : "string"
            },
            "card" : {
                "type" : "string",
                "title" : "string",
                "subtitle" : "string",
                "content" : "string"
            },
            "shouldEndSession" : boolean
        }
    }

Explanation of response data:

1. version: see #6 above

2. response: object with the response data from the application service

a. outputSpeech: contains the speech response to the user that the Echo would say

I. type: The type of output speech, valid type is "PlainText"

II. text: actual speech to say to the user

b. card: object contains what to render to the user's Echo companion app

I. type: describes type of card to render II. title: defines the title of the card III. subtitle: defines the subtitle of the card IV. content: defines the contents of the card

c. shouldEndSession: boolean indicating whether the session should end

If there is an error handling the input, the Echo application service should return a HTTP 500 error.

KB_0111

alexa skills kit
10 |5000 characters needed characters left characters exceeded

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

Article

Contributors

Brian@Amazon contributed to this article Justin@Amazon contributed to this article brizzlebrazzle contributed to this article