# Deleting Tags From a Provider

**URL:** <https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009>\
**Category:** Module Development\
**Created:** [February 17, 2023, 4:28pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009 "2023-02-17T16:28:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 17, 2023, 4:28pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/1 "2023-02-17T16:28:28Z")

</div>

I am using `com.inductiveautomation.ignition.gateway.tags.model.GatewayTagManager#importTagsAsync` to create tags directly and it is working great.

However if I import a folder that is already present, it doesn't remove any tags not present in the new import.

I.e.

### Starting:

```python
MyFolder
- Tag A
- Tag B

```

### Import:

```python
MyFolder
- Tag B
- Tag C

```

### End Result:

```python
MyFolder
- Tag A
- Tag B
- Tag C

```

### My Desired Result:

```python
MyFolder
- Tag B
- Tag C

```

Is it possible to achieve the desired output with the current `importTagsAsync` function I am using? Or do I need to delete the tags present first?

Secondly, what method should I be looking for to delete the tags? I have tried `com.inductiveautomation.ignition.common.tags.model.TagProvider#removeTagConfigsAsync` but it doesn't look like it's removing the tags.

I appreciate any info!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2023, 5:23pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/2 "2023-02-17T17:23:08Z")

</div>

Have you tried a different collision policy? I don't know for sure, but I'd expect if your config defines `MyFolder` and you have `Overwrite`, you would, in theory, end up with your desired result?  
[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.25/com/inductiveautomation/ignition/common/tags/config/CollisionPolicy.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.25/com/inductiveautomation/ignition/common/tags/config/CollisionPolicy.html)

If that doesn't work, I don't think there is a way to do this in a single operation.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 17, 2023, 6:25pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/3 "2023-02-17T18:25:42Z")

</div>

Yeah I have been using `Overwrite` and it isn't doing what I am looking for. It is just overwriting instances of the tags present, not the folders and their contents.

If I need to do this in two operations, what would be the actual method needed to delete tags at all? The `removeTagConfigAsync` doesn't seem to be deleting the tags, even when it returns a quality of `Good`.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 17, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/4 "2023-02-17T19:49:21Z")

</div>

Some progress, it looks like `removeTagConfigAsync` may be the answer, and I am just doing something wrong.

When trying to delete the following path: `[default]MyFolder` I am getting the following error: `Error("Cannot delete root node")`

I have tried adding the `/` to the end of it as well for `[default]MyFolder/` but I get the same issue.

I am wondering if in some way it's potentially because it's a folder?

EDIT: Doesn't seem to work even if I give it a path to an atomic tag.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2023, 7:53pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/5 "2023-02-17T19:53:03Z")

</div>

How are you constructing your tagpath? I don't see a way to get that error with a valid, non-root tagpath.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 17, 2023, 7:55pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/6 "2023-02-17T19:55:38Z")

</div>

Essentialy this:

```auto
TagPath folderPath = new BasicTagPath("[default]" + tagObject.get("name").toString().replaceAll("\"", ""));
List<QualityCode> deleteQualityCodes = tagProvider.removeTagConfigsAsync(List.of(folderPath)).join();

```

Where ` tagObject.get("name").toString()` returns` "MyFolder"`, but with the quotes, so I need to remove them.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2023, 8:03pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/7 "2023-02-17T20:03:48Z")

</div>

Look closer at the constructor for BasicTagPath you're using. You're only passing a `source` argument; that's why it's not working.  
You can either pass a source and a List, or you could use a static method from `TagPathParser`, or you could create a `new BasicTagPath("default")` and then call `getChildPath(String)`, but whatever you do, the way you're doing it right now is wrong 🙂

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [February 17, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/8 "2023-02-17T21:29:01Z")

</div>

That was exactly the problem! Using `getChildPath` was the cleanest answer I think. Thank you

---

<div class="post-metadata">

**Author:** ![GregCavazos](https://avatars.discourse-cdn.com/v4/letter/g/ee7513/32.png) [@GregCavazos](https://forum.inductiveautomation.com/u/GregCavazos)\
**Post date:** [February 22, 2023, 2:48am UTC](https://forum.inductiveautomation.com/t/deleting-tags-from-a-provider/70009/9 "2023-02-22T02:48:48Z")

</div>

> [@kgamble](#):
>
> ```auto
> TagPath folderPath = new BasicTagPath("[default]" + tagObject.get("name").toString().replaceAll("\"", ""));
> List<QualityCode> deleteQualityCodes = tagProvider.removeTagConfigsAsync(List.of(folderPath)).join();
> 
> ```

I have a very similar application, I am importing with system.tag.importTags(), but as stated above when a tag doesnt exist in the new set, it doesnt get deleted.

What would be the best approach? I want to delete all UDT definitions before importing the new ones.

`system.tag.importTags(filePath, "[" + provider + "]_types_", "Overwrite")`
