# Source maps are not being removed

**URL:** <https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749>\
**Category:** APM\
**Tags:** rum\
**Created:** [February 16, 2023, 2:08pm UTC](https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749 "2023-02-16T14:08:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casper\_Aangeenbrug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_aangeenbrug/32/117178_2.png) [@Casper\_Aangeenbrug](https://discuss.elastic.co/u/Casper_Aangeenbrug)\
**Post date:** [February 16, 2023, 2:08pm UTC](https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749/1 "2023-02-16T14:08:01Z")

</div>

**ELK stack version** : 8.5.2

**Describe the bug**  
I was testing the RUM agent and I realized that some of the source maps that I uploaded are incorrect. To mitigate this, I wrote a Python script that removes all source maps that belong to my app. However, none of them are actually being removed. Even though I get responses with status code 200.

**To Reproduce**  
Steps to reproduce the behavior:

1. Use this script (or test the DELETE endpoint yourself) and set the missing variables (URL, API\_KEY, APP\_NAME):

```python
import requests

AUTH_HEADER = f"ApiKey {API_KEY}"

def get_source_maps():
    return requests.get(f"{URL}/api/apm/sourcemaps", headers={
        "kbn-xsrf": "true",
        "Authorization": AUTH_HEADER,
    }).json()['artifacts']

def remove_source_maps():
    for source_map in get_source_maps():
        source_map_id = source_map['id']
        if APP_NAME not in source_map_id:
            continue
        
        r = requests.delete(f"{URL}/api/apm/sourcemaps/${source_map_id}", headers={
            "Authorization": AUTH_HEADER,
            "kbn-xsrf": "true",
            "Content-Type": "application/json"
        })

        print(r, source_map_id)

remove_source_maps()

```

1. Upload some source maps
2. Run it
3. Notice that you get responses with status code 200
4. Run it again and it will still find the source maps that you tried to remove

**Expected behavior**  
Source maps should actually be deleted.

**Actual behavior**

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/7/17236ba59d927ac34fa1440db8b622de73a49958.png)

Run it again and it says that it worked, but really it did not.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/7/17236ba59d927ac34fa1440db8b622de73a49958.png)

---

<div class="post-metadata">

**Author:** ![Casper\_Aangeenbrug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_aangeenbrug/32/117178_2.png) [@Casper\_Aangeenbrug](https://discuss.elastic.co/u/Casper_Aangeenbrug)\
**Post date:** [February 20, 2023, 1:20pm UTC](https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749/2 "2023-02-20T13:20:51Z")

</div>

It is worth noting that every 'source\_map\_id' would result in a status code 200 response. I do not expect a delete request with an invalid source map identifier to result in an OK response.

> [@Casper\_Aangeenbrug](#):
>
> `r = requests.delete(f"{URL}/api/apm/sourcemaps/${source_map_id}"`

---

<div class="post-metadata">

**Author:** ![Alberto\_Delgado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alberto_delgado/32/98488_2.png) [@Alberto\_Delgado](https://discuss.elastic.co/u/Alberto_Delgado)\
**Post date:** [February 20, 2023, 3:33pm UTC](https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749/3 "2023-02-20T15:33:34Z")

</div>

Hi @Casper_Aangeenbrug,

Thanks for reaching out!

1. You should remove the $ next to the {source\_map\_id}
2. Make sure the source\_map\_id doesn't contain blank spaces.

```auto
import requests

AUTH_HEADER = f"YOURKEY"
URL = f"http://YOURURL:5601"
APP_NAME = f"YOURAPPNAME" # in my case I used Apm Rum Test-0.1.0

def get_source_maps():
    return requests.get(f"{URL}/api/apm/sourcemaps", headers={
        "kbn-xsrf": "true",
        "Authorization": AUTH_HEADER,
    }).json()['artifacts']

def remove_source_maps():
    for source_map in get_source_maps():
        source_map_id = source_map['id']
        if APP_NAME not in source_map_id:
            continue
        formatted_source_map_id = source_map_id.replace(" ", "%20")
        r = requests.delete(f"{URL}/api/apm/sourcemaps/{formatted_source_map_id}", headers={
            "Authorization": AUTH_HEADER,
            "kbn-xsrf": "true",
            "Content-Type": "application/json"
        })

        print(r, f"{URL}/api/apm/sourcemaps/{formatted_source_map_id}")

remove_source_maps()

```

Cheers,  
Alberto

---

<div class="post-metadata">

**Author:** ![Casper\_Aangeenbrug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_aangeenbrug/32/117178_2.png) [@Casper\_Aangeenbrug](https://discuss.elastic.co/u/Casper_Aangeenbrug)\
**Post date:** [February 24, 2023, 3:49pm UTC](https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749/4 "2023-02-24T15:49:08Z")

</div>

Thanks! I guess that I have been programming a bit too much TypeScript lately (`${variable}`).

The only thing that is still bugging me is that the status code of the response is a bit off. Invalid input should not result in a response with status code 200, but rather with 'Not found' (404) IMO.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 17, 2023, 11:49am UTC](https://discuss.elastic.co/t/source-maps-are-not-being-removed/325749/5 "2023-03-17T11:49:12Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
