Isp - accessing request

amazon-alexa

#1

Hi All - as per the Alexa ISP doc turoprail I have been tryin to access the request mapped to ON_PURCHASE as below:
ON_PURCHASE() {
const name = this.$request.name;
const productId = this.$alexaSkill.$inSkillPurchase.getProductId();
const purchaseResult = this.$alexaSkill.$inSkillPurchase.getPurchaseResult();
const token = this.$request.token;

I can see all the info in the request in the terminal but when I try and console.log both the token and the name I just get “undefined” logged. I should be getting “Cancel” in the event that a refund has taken place.

Any ideas why this is happening? Why can’t I access this data

TIA


#2

Hey @Programproductions

Could you provide the request json?


#3

HERE IS THE BUY REQUEST

“request”: {
“type”: “Connections.Response”,
“requestId”: “amzn1.echo-api.request.c9ec4473-572c-4b59-8649-7a3b90c497dd”,
“timestamp”: “2021-09-14T02:48:16Z”,
“locale”: “en-US”,
“status”: {
“code”: “200”,
“message”: “OK”
},
“name”: “Buy”,
“payload”: {
“purchaseResult”: “ACCEPTED”,
“productId”: “amzn1.adg.product.a7cda2f3-5e6a-47de-840f-c555c7816d03”
},
“token”: “treatToken”
}
}

HERE IS THE CANCEL REQUEST

“request”: {
“type”: “Connections.Response”,
“requestId”: “amzn1.echo-api.request.0a32895a-b486-4569-8f2e-05979c1fef52”,
“timestamp”: “2021-09-14T03:53:49Z”,
“locale”: “en-US”,
“status”: {
“code”: “200”,
“message”: “OK”
},
“name”: “Cancel”,
“payload”: {
“purchaseResult”: “ACCEPTED”,
“productId”: “amzn1.adg.product.a7cda2f3-5e6a-47de-840f-c555c7816d03”
},
“token”: “treatToken”
}

I can get the purchaseResult and productId no problem


#4

@AlexSwe were you able to reproduce this?


#5

Hey, sorry for the late response.

That’s weird that even name is undefined. What do you get for this.$request ?


#6

Hi Alex,

sorry for the delay in my response, I just got back to this project today.
I solved it! - I just needed an extra “request” :slight_smile:

I was logging:
const name = this.$request.name;
const token = this.$request.token;

what I needed was:

const name = this.$request.request.name;
const token = this.$request.request.token;