How to get an Alexa userId?

You are doing it right. This amzn1.ask.account.[unique-value-here] is in-fact the full userId. You can observe this for yourself by enabling your skill from an Echo, logging several requests to your alexa skill, and observing that the userId between these requests is the same value.

Per the JSON Reference:

userId: A string that represents a unique identifier for the user who made the request. The length of this identifier can vary, but is never more than 255 characters. The userId is automatically generated when a user enables the skill in the Alexa app.

Note: Disabling and re-enabling a skill generates a new identifier.

If you only need to persist user attributes between sessions, this value will be sufficient and you can use it to uniquely identify this user so long as they have the skill enabled.

If you need to link an account, the value you're looking for is accessToken and lives in that same user object following successful account link. Per the same JSON Reference as above:

accessToken: a token identifying the user in another system. This is only provided if the user has successfully linked their account. See Linking an Alexa User with a User in Your System for more details.


Well, turns out I was doing everything correctly (for once). The reason why the userId was literally amzn1.ask.account.[unique-value-here] was because I was testing it on a "Alexa Start Session" test event in the AWS Lambda console. When I asked my Echo Dot to launch the skill, it generated the actual key. Problem solved.