How to get thing-id result for item "put" to HealthVault?

Sep 21, 2012 at 5:59 PM
Edited Sep 21, 2012 at 6:16 PM

When doing a put or update of a "thing" to HealthVault, is it possible to get the "thing-id" tag just assigned to this new object by HealthVault, as a return value?

The Weighter demo app uses the (void) method:

template.makeRequest(request);
// no idea what our <thing-id> is

what I want instead would be e.g.:

String myThingId = template.makeRequest(request);
// now we can edit/delete this object on HealthVault using <thing-id>myThingId</thing-id>

(The reason for asking is that I wish to avoid being forced to re-get everything off the server merely to determine the <thing-id> tag of my latest object -- the nearest workaround I can think of would be to pull down the list of <thing> objects sharing the same <type-id> as the <thing> you just uploaded, then grab all the <updated><timestamp> values, find the latest, then the <thing-id> for the object with the latest update timestamp would be the best guess/most likely match to the actual object just uploaded)

Thank you for any suggestions

Coordinator
Sep 21, 2012 at 7:29 PM

In this case you will need to create a RequestMarshaller (probably incorrectly named, it's really a response marshaller).  The marshaller would parse out the thing-ids from the response and return a list.

I don't know the best way to handle/parse on Android.  I created a bunch of Jaxb wrappers around all of HV's methods and types for folks doing java work server side, but Android can't grok them.  If I knew of an easy way to do this for Android, I would happily do it.

For now, your marshaller will have to parse the XML from the PutThings call (which contains the thing-ids) and return the list.  Have a look at the getWeights() method in WeightActivity to get an idea how it's done.  I'm not sure why I didn't use XPaths in that code.

Here is what a PutThings response looks like.  You can see the thing-id returned, as well as the version-stamp.

<response>
  <status>
    <code>0</code>
  </status>
  <wc:info xmlns:wc="urn:com.microsoft.wc.methods.response.PutThings">
      <thing-id version-stamp="0d6a3438-1d33-4a2f-a82e-fdea9beaac9e">6f330626-c10c-4d35-872d-d1a40985f911</thing-id>
  </wc:info>
</response>

--Rob

 

Sep 24, 2012 at 10:17 AM
Edited Sep 24, 2012 at 10:22 AM

Thanks Rob for the usual fast response.

Sounds good, I'll start with getWeights() from Weighter demo, but use "PutThings" instead of "GetThings", make a few additional mods as required and see if I can get something working -- may have some more questions a bit later, hope you don't mind!

--Steve

Sep 24, 2012 at 12:37 PM

Confirmed working, thanks again Rob -- much easier than I expected.

Nov 11, 2014 at 1:25 PM
Other way Just use below code after insert..

string LastUpdated = l_BloodPressure.Key.Id.ToString();


Thanks