-3

I am trying to make an Alexa skill using python backend. I am using amazon developer console to create model and code backend.

I want to retrieve user email address. I would appreciate if you could provide me with sample code. I tried many methods but none were working.

here are some codes I tried : https://github.com/alexa/alexa-skills-kit-sdk-for-python/tree/master/samples/GetDeviceAddress

I know this is device address but this was also not working, and I thought if i could get address I can get email.

Everything mentioned online is for Node, and I want to make my backend on python

1 Answers1

0

As specified in the official documentation you need to make an API call to the ASK.

For email you need to call your api_endpoint followed by /v2/accounts/~current/settings/Profile.email

For me endpoint is : https://api.eu.amazonalexa.com therefore the complete url becomes : https://api.eu.amazonalexa.com/v2/accounts/~current/settings/Profile.email

As far as adding the token to authorize the request it can be done by using the requests library by passing header to the get request. You can learn more about that from here

The final code should then look something like this :

    #Fetching access token
    accesstoken = str(handler_input.request_envelope.context.system.api_access_token)

    #Fetching user emailaddress from ASK API
    endpoint = "https://api.eu.amazonalexa.com/v2/accounts/~current/settings/Profile.email"
    api_access_token = "Bearer " + accesstoken 
    headers = {"Authorization": api_access_token}
    r = requests.get(endpoint, headers=headers)
    email = r.json()

Hope this helps, Cheers!

White Mars
  • 116
  • 1