How to test my published LEX bot on a REST CLIENT
Asked Answered
P

1

15

I have created my lex bot and published it. I am now trying to test it out from a rest client.

The idea is once working from rest client ,i can integrate this with my custom UI using rest calls.

enter image description here

I am using this request body from posttext as per this link http://docs.aws.amazon.com/lex/latest/dg/API_runtime_PostText.html

When i am using this from rest client i am getting Missing Authentication Token.

enter image description here

The end point url used is https://runtime.lex.us-east-1.amazonaws.com

Should i add something in the authorization header like AWS Signature or something else to make this work.

Philodendron answered 4/7, 2017 at 10:35 Comment(1)
Did you check out Authentication and Access Control for Amazon Lex?Lavernelaverock
R
12

You need to include an AWS Signature in the Authorization tab, containing the details of an IAM user that has access to run your Lex bot.

Steps: 1. In AWS go to IAM -> Users -> Add User

enter image description here

  1. Give it a Username like "myBotUser" and select an Access Type of "Programmatic access". Hit Next:Permissions.

enter image description here

  1. Hit Create Group to create a group to give permissions to the user.

enter image description here

  1. Give it a name and then filter the policies for Lex - and select "AmazonLexReadOnly" and "AmazonLexRunBotsOnly".

enter image description here

Hit Create Group.

  1. Then hit "Next: Review".
  2. Then hit "Create User" - and your IAM user is ready. You'll see an Access key ID and a Secret Access Key.

  3. In Postman, in Authorization, select AWS Signature and enter in the Access key ID and the Secret Access Key, along with an AWS Region of "us-east-1" and a Service Name of "lex":

enter image description here

  1. Make sure you're body is as required (here I'm just sending text):

enter image description here

Hit Send and you should get a response like this:

{
    "dialogState": "Fulfilled",
    "intentName": "yourIntentName",
    "message": "A response for that intent",
    "responseCard": null,
    "sessionAttributes": {},
    "slotToElicit": null,
    "slots": {}
}

Update

Note also - the POST url would be in format:

https://runtime.lex.us-east-1.amazonaws.com/bot/MyBotName/alias/myMyAlias/user/aUniqueUserID/text and it should be a POST

Also make sure the header Content-Type is application/json, as is the body.

Rutilant answered 10/7, 2017 at 12:49 Comment(10)
Did all this . i am getting this error "Error while sending request:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'runtime.lex.us-east-1.amazonaws.com' is not a valid http header field value" . Is this because the endpoint url is not correct? I f so what should be the right url to call a published lex bot having bot name and alias name.Philodendron
i am using the same.. i have added the screen shot in the questionPhilodendron
{ "inputText": "i want to raise a ticket", "sessionAttributes": { "string" : "string" } }Philodendron
the request is not going i guessPhilodendron
Hmm. Can you post the postman json of the request (just remove the keys if they're in it)Rutilant
Let us continue this discussion in chat.Philodendron
POST /bot/test/alias/lexTestChat/user/unique123r/text HTTP/1.1 Content-Type: application/json Host: runtime.lex.us-east-1.amazonaws.com​ X-Amz-Date: 20170712T123140Z Authorization: AWS4-HMAC-SHA256 Credential=xxxxxxxxxx/20170712/us-east-1/lex/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Cache-Control: no-cache Postman-Token: 46f48b78-ab05-1f1b-5f37-bceb4e02dc9e { "inputText": "i want to raise a ticket", "sessionAttributes": { "string" : "string" } }Philodendron
is there anything specific in user we have to give or can it be any random value ?Philodendron
See the chat discussionRutilant
Check the chat, I've posted json for postman that should workRutilant

© 2022 - 2024 — McMap. All rights reserved.