1

Xively provisioning - how does an app request a device feed ID and key?

On the "Provisioning" page it says: "8 An application prompts the user for the serial number of the device they have just activated, the application uses a Master Key and the device serial number to request the device Feed ID and key from Xively."

This seems to suggest there's an API to do this, but I can't find it!

Does anyone know where this is in the docs or how to do this?

a4o
  • 81
  • 4

2 Answers2

0

To get a feed ID for the device one need to make a Read Device request.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
  • Thank you. I saw that, but thought there must be some other method, because it says "request the device Feed ID and key". Read Device does not return a key. How would you get the key? – a4o Jul 20 '13 at 00:13
  • @a4o that's really option, you don't have to do that. You can just use the master key to start with. The idea of using device's key is sort of an extra security measure. – errordeveloper Jul 22 '13 at 09:36
  • @a4o actually you do get `api_key` field when you do `GET` on `https://api.xively.com/v2/products/:product_id/devices` or `https://api.xively.com/v2/products/:product_id/devices/:dev_serial`, it's just a bug in the docs. – errordeveloper Jul 22 '13 at 09:44
0
  1. Go to Account | Settings | Add a master key with Read/Update all permissions.

2) Note down the master key. Now to read all the devices (instances) created for a product (template) use API and key from (1)

This API will return all devices with feedId and device keys.

A working example with Curl


include ('sensorui.inc');
    include(APP_CLASS_LOADER);

    // script to list all devices for a product

    $url = "https://api.xively.com/v2/products/XwYNEGj4epo7HXNM0DGK/devices" ;



    // API KEY
    // This is master key API (from Account | settings page)
    // for some reason (bug?) READ only key does not work!
    $xheaders = array("X-ApiKey" => "your_master_key");
    $cookies = array();

    $curl = new \com\yuktix\util\curl\Wrapper($url,$cookies,$xheaders) ;
    $curl->setCookies($cookies);
    $curl->setXHeaders($xheaders);
    // $curl->setDebug();


    $response = $curl->doGet();
    print_r($response);

    $code = ($response["code"] != 200) ? 1 : 0 ;
    return $code ;

Returns

rjha@kubuntu13:~/code/bitbucket/sensorui/scripts/xively$ php list-product.php 
Array
(
    [code] => 200
    [response] => {"totalResults":2,"itemsPerPage":30,"startIndex":1,"devices":[{"serial":"SVSN001","activation_code":"xxx","created_at":"2014-02-02T15:05:37Z","activated_at":"2014-02-02T15:12:41Z","feed_id":xxx,"api_key":"xxx"},{"serial":"SVSN002","activation_code":"xxxx","created_at":"2014-02-02T15:05:37Z","activated_at":null,"feed_id":xxxx}]}
rjha94
  • 4,292
  • 3
  • 30
  • 37