Customers - claiming and unclaiming

@G65434_2 I used the spark-api.js and not just the cloud. I’m not actually creating a spark instance either. I’m doing this:

sparkLogin(function(data) {
      console.log(data);
      getClaimCode(data.access_token);
});

And then I do this:

var claim_code = "";
function getClaimCode($accessToken)
{
    var jqxhr = $.ajax({

        method: "POST",
        url: "https://api.particle.io/v1/device_claims",
        data: { "access_token": $accessToken }

    }).then(function( data, textStatus, jqXHR ) {
        console.log("Sucessfully got claim code");
        console.log(data);
        claim_code = data.claim_code;
        $("#sendClaimButton").show(); // just a button to send the code now that I have it
        // Now switch to a device in listening mode and attempt to claim it by clicking the button
    }, function( jqXHR, textStatus, errorThrown ) {
        console.log("Failed to get a claim code");
        console.log(textStatus);
        console.log(errorThrown);
    });
}
// Bind a button
$("#sendClaimButton").bind("click", sendClaimClick);

Then of course the SoftAP

function sendClaimClick()
    {
        var sap = new SoftAPSetup();
        sap.setClaimCode(claim_code, callback);
        function callback(err, dat)
        {
            if(err)
            {
                throw err;
            }
            console.log(dat); // currently only outputs {r:0}
        }
    }

That’s pretty much all of it sans the html for the button and js includes for jQuery and particle files. It doesn’t include any keys or tokens either and as far as I can tell should work. Again, the above doesn’t use customers. As a note, I to have a complete system of claiming devices using the cloud api, but I have to use my parent / company account’s tokens to get this to work since I do create customers. I’ve not had any issues claiming any photons with it either.

@kefir135 that is true, you cannot currently unclaim a device using any of the api’s (cloud, js or native). You have to email someone at Particle directly to take care of this, until it’s completed.