xively

Xively provisioning: Activating a device more than once/fetching API key & feed Id a second time


I am working with testing out provisioning for an embedded device where I can't save the API key and feed ID when power cycling.

After activating the product once, I get 403 forbidden when trying to fetch the device API key and feed id for the second time, even though I am supplying a master API key (with read permission) when making the request. The request works however when using API key belonging to the device, which is an inadequate solution considering I don't have access to that API key.

My GET request is formatted as follows:

GET /v2/devices/<activation code>/activate.csv HTTP/1.1
Host: api.xively.com
X-ApiKey: <master API key>
Content-Length: 0

So, is there a way for an already activated device to receive its API key and feed ID?


Solution

  • A device can only be activated once. However, if you have a master key, retrieving the devices API key should be pretty easy. You say you don't know the devices feed ID, but if you used the activation endpoint I imagine you know its serial number?

    If you do know its serial number try making a GET request to https://api.cosm.com/v2/products/PRODUCT_ID/devices/DEVICE_SERIAL with your master API key in the X-ApiKey header.

    This should return the following JSON, with you feed ID and API key.

    {
        "device": {
            "serial": "SERIAL",
            "activation_code": "ACTIVATION_CODE",
            "created_at": "2013-05-05T18:11:42Z",
            "activated_at": "2013-10-18T16:25:07Z",
            "feed_id": FEED_ID,
            "api_key": "DEVICE_API_KEY"
        }  
    }
    

    You should also be able to make consecutive activations, if you pass the API key you got from the first activation.