Creating a New Customer (two legged auth) - Now Working

@Kevin were you able to get this working? Your cURL request looks good. scope is the key and customer=customer@example.com would be the value of the query param for use in a form.

If you are still having problems, DM me your org name, customer email, and client ID you are using and I can look into it more.

Jeff

Hi there, I am getting the error ā€œOrganization not found.ā€ when trying to create a customer using curl. After reading above, I think Iā€™m probably entering my organization in the URL incorrectly.

Can someone please tell me where I can find my ā€œ:orgSlugā€?

Hey Dan,

Your confusion is totally valid ā€“ in our recent update to the console, we have since abstracted the concept of organizations from the front-end. If you created the product pre-console, then you created an organization and set its name. The slug would just be the downcased and dasherized version of the name (i.e. ā€œJeff Organizationā€ => ā€œjeff-organizationā€).

If you just created your product, the slug of the organization is the same as the slug of the product. You can find this in the console, when you navigate to any product-specific URL. It is the downcased/dasherized version of the product name + the product version. For example, on the devices page for a product called ā€œFooā€ with version ā€œv1ā€, the URL would look like: https://console.particle.io/foo-v1/devices, and the slug would be ā€œfoo-v1ā€.

Does this help?

Jeff

Yes, thankyou for the clarification - that makes a lot more sense now. The docs probably should mention this!

1 Like

Hey @jeiden,

Adding a customer via the API now seems to work for me, with a response similar to what I was expecting. However, even after waiting a day to update, I still cannot see any of the added customers in the console. Is there something Iā€™m missing?

Hey @dan.s,

The customers will actually appear when they have claimed ownership of a device. This is definitely confusing, and something we have a ticket to improve. It would make more sense to show those customers as soon as they are created.

For now though, claim a product device and youā€™ll see the customer appear.

Jeff

Sorry to exhume this post. Iā€™m working through this process for simple auth. My end goal is to get a basic prototype going destined for an ionic app (angular). I am having trouble working out the curl commands to go through creating a client; customer; token etc in an effort to gain a clear understanding of what all the steps are. There is great information but itā€™s scattered between the guide, the reference and the community forum. Take this post. This is the only reference anywhere that explains what organization is, or where to find it. However, copying the string straight from the browser console, when I try:

curl -X POST -H ā€œAuthorization: Bearer 1234ā€ -d name=ā€œIonicMobileAppā€ -d type=installed organization=mXXXXp-v1 https://api.particle.io/v1/clients

curl: (6) Could not resolve host: organization=mXXXXp-v1

although it does return an otherwise sensible looking object:

{
ā€œokā€:true,
ā€œclientā€:
{
ā€œnameā€:ā€œIonicMobileAppā€,
ā€œtypeā€:ā€œinstalledā€,
ā€œsecretā€:ā€œ1234ā€,
ā€œidā€:ā€œionicmobileapp-8868ā€
}
}

And when I try:

curl -X POST -u ionicmobileapp-8868:1234 -d email="me@email.com" -d password=ā€œmyPAssWrdā€ https://api.particle.io/v1/org/mXXXXp-v1/customers
{ā€œokā€:false,ā€œerrorā€:ā€œNot Foundā€}

Iā€™m more from the hardware world, so I know much of this may seem obvious. I donā€™t suppose anyone could point me at a guide that might help. Itā€™s just not fitting together. ANd after this Iā€™ll have to figure out how to squeeze this into Angular 2 for more fun and games?

Unless someone has done this in Angular 2 already. Would be nice to cut out the middle man!

Thanks forum.

Al.

Hey @monkey - this reference documentation should be helpful to you: https://docs.particle.io/reference/api/#create-a-client

1 Like

Edit to my own question, in the hope that this might be helpful for others.

If like me, you're having trouble creating customers or tokens, with errors like: {"ok":false,"error":"Organization not found for user's role."} or {"ok":false,"error":"Not Found"} refer to rickkas7 s post. There is an very succinct explanation of tokens and scope, which is not covered in the documentation.

Cheers,

Al.

1 Like

Can we incorporate this into the docs? @rickkas7?

1 Like

Iā€™m trying to get a product through initial prototyping but Iā€™m struggling with the js api. I used a test email address to create an account and claim a device etc etc to test out the process. All worked fine. Iā€™m now expanding it into an ionic app. But as soon as I enter a new ā€˜testā€™ email address pretending to be a new customer, I run into problems. If I create a user with the product client id & secret (with limited scope), that works. This is the method given in the docs. But I canā€™t subsequently login as that user using the same client id & secret? (Why is this?) Strangely, I can log in using id+secret=particle-api or anything else for that matter. But the killer is that I canā€™t then generate a claim code, at all?! Whatā€™s going on? This is so confusing. I would expect to create a Particle object; pass my product specific client credentials into the constructor and use this for everything. What reason if any is there to use blank/generic client id&secret. And is there a case where more than one Particle objects will be needed within an app?

Iā€™m using ionic by the way, so as far I can gather, I need to use the restricted scope client credentials approach. Iā€™ll keep working on it in the meantime, but Iā€™d really appreciate some expert advise.

Cheers,

monkey.

@monkey ā€” as always, specific code snippets will help our team get a better understanding of where the problem lies.

Iā€™m not exactly sure how your requests look, but Iā€™ll recap the process from our docs. After a customer (remember that customers are different than users) is created and the device claimed, the only remaining piece is authenticating API requests correctly to interact with that customersā€™ devices. To do this, youā€™ll need to generate access tokens scoped to the customer. This will allow you to do things like call a function, check a variable, etc. on behalf of the customer from your server or mobile/web app.

Here is our API reference documentation on how to create customer-scoped access tokens using your OAuth credentials: https://docs.particle.io/reference/api/#generate-a-customer-scoped-access-token.

It is also described in the Two-legged auth guide here: https://docs.particle.io/guide/how-to-build-a-product/authentication/#7-interact-with-customer-39-s-device-1.

Good luck,

Jeff

Yes, it works! Customers are different than users. Because the notion of customers was not included in the javascript api, I made the assumption / oversight that users were equivalent to customers. Having corrected that assumption, it now works. Thanks.

1 Like