List Customers For a Product

Hey guys,

I have started successfully adding customers to my product using this command:
https://docs.particle.io/guide/how-to-build-a-product/authentication/#3-create-a-customer-1

Unfortunately none of the customers I make are showing up in my product’s dashboard. Im also trying to access them with the following curl command:
curl -X GET --user clientID:xxxxxclientSecretxxxxx https://api.particle.io/v1/products/productID/customers

The response claimes there is a “malformed auth header” but it is formed the same as when I create a user…
{
“error”: “invalid_request”,
“error_description”: “Malformed auth header”
}

This has since gotten stranger… Not my entire ‘Authentication’ tab is missing for my product from my console. (It looked like a little thumbprint)

@jeiden any clue?

Maybe try to clear cache on your browser or incognito it…It appears that the auth icon has changed. Last one is the new icon.

The authentication tab not showing up is somewhat fixed, I can click where it ought to be and get to the page, the icon just isnt visible. Im sure its my cache or something. The more important issue of not being able to list customers is unchanged though. It still just says “malformed auth header”. I also tried treating it like a Bearer token, which I didnt think would make sense, and it failed still.

Is there something other than this call I should be trying:
curl -X GET --user clientID:xxxxxclientSecretxxxxx https://api.particle.io/v1/products/[productID]/customers

You are making the request with your productIDSlug correct?

GET /v1/products/:productIdOrSlug/customers

I believe so. I am using the same 4 digit value I used in the command to make a customer for my product. It says its my productID in the console, not sure what the ‘Slug’ is.

I think it is older term to be honest I would use the ProductID as well. Have you tried with the access_token for your account? Since it complaining about the header maybe it is expecting the auth header with a token instead. I have noticed that OAuth use is usually limited to creating users and tokens then things go back to access_tokens from there. The Docs don’t specify which auth model to use so if you do figure it out I think a docs PR may be appropriate!

Ahh cool, thats good to know. I have tried this:
curl -X GET -H “Authorization: Bearer xxxxClientSecretxxxxxxxx” https://api.particle.io/v1/products/[clientID]/customers

That gives me the following though:
{
“error”: “invalid_token”,
“error_description”: “The access token provided is invalid.”
}

Interestingly if I try this:
curl -X GET -H “Authorization: OAuth xxxxclientSecretxxxxx” https://api.particle.io/v1/products/[clientID]/customers

I get the same ‘Malformed auth header’ as when I try this:
curl -X GET --user clientID:xxxclientSecretxxx https://api.particle.io/v1/products/[clientID]/customers

All of the credentials Im using here are from a client I made in the authentication tab with ‘full permissions’:

When you say “the access_token for your account” do you mean those credentials from the authorization tab or should I use the command outlined here to make an access_token for my developer account: https://docs.particle.io/reference/api/#generate-an-access-token

Just in case that is what you meant, I tried it. I was able to generate an access token using my developer account credentials and the following command:
curl https://api.particle.io/oauth/token -u particle:particle -d grant_type=password -d username=myEmail@email.com -d password=myPassword

I then tried to list customer using both of the following:
curl -X GET -H “Authorization: OAuth xxxaccessTokenxxx” https://api.particle.io/v1/products/[productID]/customer

and

curl -X GET -H “Authorization: Bearer xxxaccessTokenxxx” https://api.particle.io/v1/products/[productID]/customer

they both gave me this:
{
“ok”: false,
“error”: “Not Found”,
“device_name”: “narwhal hunter morphing boomer penguin”
}

Thanks for the help guys! Im just super confused :smile:

Thanks for the heads up on the icon problem, I am fixing that now!

OK, the icon should now be fixed. Sorry for the mixup!

@ShotLine,

When you GET customers, you should be using an access token from your Particle user account. Your second request is not quite hitting the right endpoint, you have:

curl -X GET -H "Authorization: Bearer xxxaccessTokenxxx" https://api.particle.io/v1/products/[productID]/customer

but customer should be changed to customers (plural).

The OAuth Client ID and secret are used to generate access tokens. These access tokens can then be used to make requests against the API

That should do the trick

Awesome I think that worked thanks! I knew it would be something small on my end lol.

One last question. It returns what looks like a valid response but is empty. I do have customers created but I dont have any that have devices associated with them. Do customers only show up here, and in the dashboard, after they have devices associated with them?

Thanks again for all the help!

@ShotLine that is correct! customers only show up after they have been associated with a device

Is there a tutorial for submitting a PR to update docs.particle.io? I would be happy to add the detail to the Cloud API. The token owner would need to be someone identified as being on the product team correct?

@LukeUSMC, you should be able to directly edit and file a PR when you hit the Edit :pencil: icon in the top right corner of the respective docs page.

1 Like