Getting a customer's ID

When using either the Cloud API or the JavaScript SDK, is their any way to retrieve a customer’s ID from their access_token? I am currently using a customer’s ID (available from a web-hook) as a key in a database, but have no way of knowing what a customer’s ID is from the front end.

Thanks,
Gareth

I assume you mean the device ID (24 character hex)?

It’s not possible to get the device ID from an access token, because the access token is tied to the account, not the device. There isn’t a unique mapping for any account with more than one device.

Thanks for your quick reply :sunglasses:

Actually, I do mean the customer’s ID. From a webhook, it appears as though I can gain access to a customers ID using a pre-defined webhook variable {{{PRODUCT_USER_ID}}} (https://docs.particle.io/reference/device-cloud/webhooks/#pre-defined-variables). This returns an ID that I can’t seem to get access to from the Cloud API.

When I attempt to call getUserInfo from the JavaScript SDK or the following curl command curl "https://api.particle.io/v1/user?access_token=12345", I get an empty array back. Which makes partial sense since this is a customer and not a user - however, the part that doesn’t make sense is that this customer does indeed have a user ID that the webhook has access to but I do not.

Anyone else had the opportunity to look into this?

Cheers.

1 Like

Hi GarethS,

I’ve been trying to figure out the same thing and here’s what I’ve found:
It looks like calling the JDK trackingIdentity function with your access token returns the same user ID that you get from {{PRODUCT_USER_ID}}. I haven’t had a chance to test this with multiple users yet though.

Thoughts?