Customers - claiming and unclaiming

@Dave

I sent you a PM a couple of days ago about not being able to claim a device. Although your suggestion to make the letters in the device ID lowercase was part of the problem, it wasn’t all of it! I’ve decided to reply here just in case this is useful to anyone else…

Making the letter lowercase did return a ‘success’ message via the CLI when trying to claim, however the device still didn’t show up in my list. I’ve since realised this is because the CLI doesn’t let ‘customers’ claim devices (I was logged in as one of my test customers) - https://github.com/spark/particle-cli/issues/166

Now, the reason I tried to use the CLI was because I wasn’t having any luck using the SoftAP library to claim.
I’m now pretty confused. I’m successfully receiving a claim code via the API, then sending the claimcode using sap.setClaimCode(claimcode, key); (which I believe is successful). Is there anything further I need to be doing to complete a customer claim process? I’m having a pretty hard time with the whole customer side of things and not finding a lot of information on it. Further more @jeiden has told me that there isn’t currently a way to ‘unclaim’ a customer device which is a concern for me as I’m days away from installing devices for customers that are currently claimed to my ‘test customer account’.

Sorry about the long message but some answers to these questions would be hugely appreciated - I’m using simple auth (not two legged).

1 Like

@G65434_2, are you also sending the device Wi-Fi credentials? The device will need the claim code + Wi-Fi credentials to be able to send the code up to the cloud.

Here is the link explaining this: https://github.com/spark/softap-setup-js#configuring-the-device-for-a-selected-access-point.

If you’re doing this just for testing purposes, you can just use the code mentioned above. However, if you are building an app that customers will use, you’ll need to first scan for Wi-Fi access points, then configure the device for that access point using Wi-Fi credentials provided by the customer. See below for the full flow of events needed for simple auth setup.

Can you try this if you haven’t already and let me know if it works? If it’s not working, providing the ID of the device + a description of the on-board LED while trying to connect would be very helpful.

I’m really sorry this has been a confusing process for you. Once the Electron ships, working on better documentation and a streamlined process for building JS based product applications is high on our to-do list.

Jeff

3 Likes

Thanks @jeiden

Sorry for not explaining my situation a bit clearer, I am indeed sending WiFi credentials and everything is working in that respect, the device does connect to the internet afterwards as well. Since posting my last message I’m beginning to suspect that there may be a bug in the SoftAP JS library that converts the device ID to uppercase before hitting the API with a claim request? The unusual thing is that one of my devices was able to be claimed by a customer account (didn’t have letters in device ID) and two remaining devices have not been able to be claimed (they both have letters in their device ID which are uppercase when the SoftAP returns the device ID via sap.deviceInfo).
I can also confirm that for both of these devices, the SoftAP library returns ‘true’ for claimed, even though they don’t show up in the customers device list.

@G65434_2,

A couple things that might be off here:

  1. Are you sure that you are using the product specific claim code generation endpoint, not the user claim code generation API endpoint? The endpoint you want to use is: https://docs.particle.io/reference/api/#generate-device-claim-code-for-product

  2. Are you sure that when using the endpoint above, you are hitting it with a customer access token, specifically the customer that will be claiming the device?

Jeff

1 Like

Hi @jeiden

Yes, here is my ajax request in full just in case it’s handy to anyone else, is this correct?
To answer your question, I’m certainly using the customer access token.

jQuery("#wifi-config-button").click(function(e){
  var jqxhr = $.ajax({
  type: "POST",
  url: "https://api.particle.io/v1/orgs/myorg/products/myproductslug/device_claims",
  data: {
    access_token: accessToken
  } 
})
.done(function(data) {
  window.location = "http://setup.mycompany.io/#" + data.claim_code;
})
.fail(function() {
});
  e.preventDefault();
});

Hi @G65434_2 -
I have been able to claim devices via a customer account. The process by which I do that involves:

  1. First claiming the device with the my primary account - the one associated with the company. I use the CLI for this, but I assume you could do it via the Cloud API using the primary accounts token. Note: you will need to have set up a company and a product so you have the org slug and product slug for the following steps.
  2. I then create a customer using the Cloud API for the company.
  3. Then, using the created customer token I get an access token for that customer.
  4. You have to do the above steps while online, then using the SoftAP, you can set up the wifi credentials and pass in the claim code via sap.setClaimCode([claim code], callback).

Note, I’m doing the above knowing ahead of time what the device ID is, so you may have to bounce back and forth with the SoftAP to get it to work.

That looks correct. Can you try passing this claim code to the softAP library -> device one more time?

@1inarow Why step #1? You shouldn’t need to claim the device to a user account first.

@jeiden That’s just what I did to test all of the hardware with most recent firmware before rolling it out. Perhaps it’s completely unnecessary.

Thanks @1inarow

As far as I’m aware, that’s exactly what I’m already doing, minus step 1.
@jeiden, when you looked at my device IDs did something indicate to you that I had tried to claim these with a user account, rather than a customer account?

Correct, yes. There was a user_id assigned to each device. However, the value of that field in the database was actually a customer_id. This indicates that somewhere in the process, a claiming endpoint for a user was hit with a customer access token, instead of a customer-generated claim code being sent to the device, then published to the cloud.

Admittedly, we should block this from occurring on our side, or just make it “work” by assigning a customer_id instead of a user_id

1 Like

Thanks @jeiden I’m not sure what you can do from your end but are you able to clear the claim history so I can try again?

I’ve just unclaimed one of my other devices (assigned to that org and product) from my user account and successfully claimed it to a customer account using my existing process.
I can confirm that this device did NOT have any letters in it’s device ID.
Now, I may be barking up the wrong tree here but there is a strange connection between devices with an ID containing a letter and problems occurring in this process…

@G65434_2 I have claimed several devices with letters in them. @jeiden had to unclaim them for me. They were all lower case.

1 Like

Can you send me the claim codes that did not work for the devices with letters?

Furthermore @jeiden, I did try to claim these devices unsuccessfully later with the CLI, (using a customer account) perhaps that is a cause for the user_id being incorrectly assigned?

Thanks @1inarow, perhaps it’s mere coincidence…

@jeiden

I just realised that when I log a user into my webapp, I’m actually using ‘particle-api’ as both the client_id and client_secret, meaning that perhaps the temporary access token and claim code is generated with the wrong scope…
Feel a bit stupid here as I should have picked this up earlier, in this case should I have my webapp client ID here? But shouldn’t the secret not be visible unless it’s ‘particle-api’?

Try it again with your actual credentials, and send these codes to the device. Let me know if that works.

Ok, this is was I was previously doing to login to my webapp:

I’ve since changed client_id and client_secret to the values that were returned when I first created the oauth client for my webapp. Now I can’t login using the login credentials for a customer created using that client_id…

Not too sure what I’m doing wrong now.

@1inarow any thoughts on this? How do you login to your own webapp?

This section in the docs makes me think there might be something I’m missing out…
https://docs.particle.io/guide/how-to-build-a-product/authentication/#login-with-particle