Search code examples
fiware-orionfiwarefiware-wirecloud

Make a wirecloud query using NGSI API


I'm trying to make a query using NGSI API in my Wire Cloud widget but always fails and I don't receive anything:

var descubrimiento = connection.query([{
       isPattern: true,
       id: MashupPlatform.prefs.get('idfuente')
   }],
   null,
   {
      flat: true              
   }
);

connection is the object where I have the connection with the context broker and it works fine. Also if I make the query with the NGSI10 RESTful API via RESTclient I receive the data that I want but with the wirecloud NGSI API in my widget it is imposible to make the query.

Someone has this problem too?


Solution

  • Take a look at this tutorial about how to use the Orion Context Broker from WireCloud.

    The main problem is that you're assuming the method the query response is returned synchronously while in reality is returned asynchronously. For being able to read the returned data, you need to pass a onSuccess callback. This callback will be called as soon the response from the Orion server is available. The data returned by Orion will be passed as the first parameter of the onSuccess callback function (see the referenced documentation for examples about how the returned data is formatted). E.g:

    connection.query([{
           isPattern: true,
           id: MashupPlatform.prefs.get('idfuente')
       }],
       null,
       {
          flat: true,
          onSuccess: function (descubrimiento) {
              ...
          }
       }
    );