# \[Solved\] How to map deviceIDs

**URL:** <https://forums.losant.com/t/solved-how-to-map-deviceids/418>\
**Category:** Help\
**Created:** [February 22, 2017, 10:16pm UTC](https://forums.losant.com/t/solved-how-to-map-deviceids/418 "2017-02-22T22:16:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastien\_Fouss](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Sebastien\_Fouss](https://forums.losant.com/u/Sebastien_Fouss)\
**Post date:** [February 22, 2017, 10:16pm UTC](https://forums.losant.com/t/solved-how-to-map-deviceids/418/1 "2017-02-22T22:16:47Z")

</div>

Hi,

I can’t find a way to solve my issue, maybe someone has an idea…

So:

- I am testing a Sigfox device
- I created a device on Losant to represent it, so I got the deviceID created by Losant
- want to trigger a Losant webhook from Sigfox server when it receives data from the device
- but the Sigfox device has a hardcoded id  
And I have no clue on how to match the webhook with the right Losant device.  
Well, I could of course introduce an intermediate layer who would do the mapping but this is not elegant.  
I could also use a tag to store the Sigfox id, but I call on regular basis the patch tags API and for some reason such a call deletes all tags before storing the tags passed by the caller, so my Sigfox id would be lost.  
The only option I see, but again not elegant, is to use a tag and get all tags before each invocation of tag patcher, so I could pass back the sigfox id tag…

Any smart advise ?

Actually the solution could be a feature request : when creating a device, next to the device id assigned by Losant, we should be able to assign a second device id.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [February 23, 2017, 7:40pm UTC](https://forums.losant.com/t/solved-how-to-map-deviceids/418/2 "2017-02-23T19:40:13Z")

</div>

This article does provide a solution for this problem:

> **[Collect, Monitor, and Visualize your Sigfox Data with Losant](https://www.losant.com/blog/collect-monitor-visualize-sigfox-data)**
>
> This guide demonstrates how to integrate Sigfox and Losant for data collection, monitoring, and visualization.

Essentially you add a tag to each Losant device with the Sigfox ID. Then in the workflow, you can use the Losant API node to find the matching Losant device based on the incoming Sigfox ID.

---

<div class="post-metadata">

**Author:** ![Sebastien\_Fouss](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Sebastien\_Fouss](https://forums.losant.com/u/Sebastien_Fouss)\
**Post date:** [February 23, 2017, 8:15pm UTC](https://forums.losant.com/t/solved-how-to-map-deviceids/418/3 "2017-02-23T20:15:15Z")

</div>

Hi Brandon, and thank you.

Well, this is what I had in mind (that’s the last part of my message).  
My problem is that I use the Patch API on a device (basically, I am using this API to set some threshold that the device is validated against), and this Patch function deletes all the device tags, and writes the one passed by the Patch API only.

In other words,

Before patch call: AttrA=“A”, AttrB="B"  
Call patch with AttrA="C"  
After patch call: AttrA="C"  
_but AttrB=“B” is gone !_

Not sure if this is a bug or deliberate, but this is quite blocking for me.

Thanks

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [February 23, 2017, 10:49pm UTC](https://forums.losant.com/t/solved-how-to-map-deviceids/418/4 "2017-02-23T22:49:38Z")

</div>

Ah, I see!

You could do a GET on the device to grab the current set of tags before using the PATCH to update them. This way you could keep existing tags when you send the new tag. The PATCH is designed so that you’d send the entire set of desired tags on each request.

If you’re unable to change how the new tags are sent, a quick workaround could be to set the mapping in the workflow globals. This is a good option for a few number of devices, but gets a little tedious to maintain as you scale up. Essentially create an entry for each device where the key is the Sigfox ID and the value is the Losant ID. The template to get the result would then look like `{{ lookup globals data.body.device }}`.

Here’s a workflow that demonstrates using the globals:

[global-id-map.flow](https://forums.losant.com/uploads/short-url/p5eNuLYsatJ3At6G8qF34iTibFU.flow) (757 Bytes)

---

<div class="post-metadata">

**Author:** ![Sebastien\_Fouss](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Sebastien\_Fouss](https://forums.losant.com/u/Sebastien_Fouss)\
**Post date:** [February 25, 2017, 6:28pm UTC](https://forums.losant.com/t/solved-how-to-map-deviceids/418/5 "2017-02-25T18:28:10Z")

</div>

Thanks for the suggestions. Not sure I want to go down first path, since this would make the operation unatomic (first get tags, then update them).  
Will dig the second option 🙂

Thank you !
