Claim_code expiration?

Hi @mtun009,

The API endpoint to create a claim code (POST /v1/device_claims) is documented here:
https://docs.particle.io/reference/api/#create-a-claim-code

I also suspect you may be confusing access tokens and claim codes.

A claim code may only be used once, for a single device, and it must be used within an hour of creation. Here’s how the flow goes:

  • Imagine you start with a Photon that has no Wi-Fi credentials, is offline, and is blinking blue. That Photon is broadcasting a Wi-Fi AP named “Photon-WXYZ”
  • Your phone or computer is connected to the internet.
  • You use your access token on that phone or computer to hit POST /v1/device_claims to create a claim code.
  • The API creates a claim code in the database that represents you as a user, and it responds with the claim code (63 characters) and an array of your currently claimed device IDs.
  • The phone or computer then disconnects from the internet and connects to the Photon’s network “Photon-WXYZ”. The phone/computer is now directly talking to the Photon, and neither device has internet access.
  • The phone/computer asks the device for its ID. If the ID matches one in the already claimed list, then there’s no need to claim. Otherwise, it sends the claim code as well as the Wi-Fi credentials directly to the Photon. The Wi-Fi password is encrypted during this transfer.
  • The Photon closes the connection with the phone/computer, shuts down its AP, and attempts to connect to the Wi-Fi network using the credentials the phone/computer sent.
  • If the Photon successfully gets on Wi-Fi and the internet and connects to the :particle: :cloud: it tells the cloud about the claim code it received.
  • The cloud looks up the claim code, finds it, and (if it’s been less than an hour) now knows that this device belongs to the user who requested the claim code a moment ago. We mark the claim code used (it can never be used again).
  • When the phone/computer lost the connection to the Photon, it reconnected to the internet and started polling the “list my devices” endpoint, waiting for that Photon’s ID to show up anew in the list of devices you own. When it sees the device in the list, it gives a success message; the setup process will give up after a certain timeout, assuming the device must have had some problem getting online.

Hope that helps!
Zachary

4 Likes