Set Claim Code Fails (-1)

I’m trying to set the claim code for a photon, and getting an error. The claim code was generated using a token generated with a customer-scope, for a particular product.

POST /set? HTTP/1.1
Host: 192.168.0.1
Content-Type: application/x-www-form-urlencoded

cc=<my claim code here>
{
    "r": -1
}

My understanding is that I would generate a code by hitting this endpoint: https://api.particle.io/v1/products/my-product/device_claims, and then connect to the device in soft ap mode, and POST to http://192.168.0.1/set, passing the claim code, like this:

POST /v1/products/<my device here>/device_claims HTTP/1.1
Host: api.particle.io
Authorization: Bearer <my customer-scoped token here>

Is that correct?

The device had previously been claimed and then unclaimed.

Normally you use the Photon/P1 Device Setup library instead, but if you want to do it manually I think you’re missing some steps. Also, the parameter to the /set must be in JSON format instead of form-urlencoded.

This page shows how to do it manually:

1 Like

Awesome, thank you for the link! I wasn’t aware of this treasure trove of documentation. Setting the claim code with the body in JSON instead of form-urlencoded now succeeds, (returning 0), but it’s not actually associated with my user. I didn’t know the expiration for claim codes, so I generated a fresh one, and set that, and it still does not show up in the console.

I wasn’t sure if the order of configuring the access point and setting the claim code mattered, so I erased the wifi networks, set the claim code and configured ap, with the same result. Should I do the factory reset described here? https://github.com/rickkas7/photonreset

Actually, I got it to work. I was missing the "Import Device into Product" step. It would have taken even longer without your documentation calling it out https://github.com/rickkas7/particle_notes/tree/master/manual-photon-claiming#add-the-device-to-the-product

It's not obvious from the documentation, but you have to add the device ID to the product before it can be claimed using two-legged auth.

Not obvious indeed.

https://docs.particle.io/reference/device-cloud/api/#import-devices-into-product

1 Like