# Missing Result ID in Annotations created with the sdk

**URL:** <https://community.labelstud.io/t/missing-result-id-in-annotations-created-with-the-sdk/223>\
**Category:** Label Studio Support\
**Tags:** annotations\
**Created:** [May 31, 2024, 3:39pm UTC](https://community.labelstud.io/t/missing-result-id-in-annotations-created-with-the-sdk/223 "2024-05-31T15:39:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stella\_Schlotter](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/stella_schlotter/32/61_2.png) [@Stella\_Schlotter](https://community.labelstud.io/u/Stella_Schlotter)\
**Post date:** [May 31, 2024, 3:39pm UTC](https://community.labelstud.io/t/missing-result-id-in-annotations-created-with-the-sdk/223/1 "2024-05-31T15:39:43Z")

</div>

I am using the labelstudio sdk to create annotations. For example like this:

```python
label_studio_result_list = [{
'type': 'rectanglelabels', 
'value': {
'x': x, 'y': y, 'width': w, 'height': h, 
'rotation': 0, 
'rectanglelabels': [
  result.names[result.boxes.cls.cpu().numpy()[idx]]]}, 
 'to_name': 'image', 'from_name': 'label',
 'origin': 'manual', 
 'original_width': result.orig_img.shape[1], 
 'original_height': result.orig_img.shape[0]
}]

ls_result = {"result": label_studio_result_list, 'completed_by': 2}
project.create_annotation(task_id, **ls_result)

```

The annotations are created without a problem. But I noticed the result id is missing in the response.

However in the UI it shows me the id. When clicking update on the task. I see that it sends a patch request to the backend with the id shown in the UI but only if I change the position of the bounding box. I need the id’s in order to make sense of relations that I add manually.

How can I solve this? Going to every task that is missing an id and clicking Update is too time consuming for me.

---

<div class="post-metadata">

**Author:** ![sajarin](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/sajarin/32/56_2.png) [@sajarin](https://community.labelstud.io/u/sajarin)\
**Post date:** [May 31, 2024, 4:32pm UTC](https://community.labelstud.io/t/missing-result-id-in-annotations-created-with-the-sdk/223/2 "2024-05-31T16:32:43Z")

</div>

You might be able to add an id to each of the annotations using a function to generate a unique id, here’s a rough example below:

```auto
import uuid
from label_studio_sdk import Client

# Connect to Label Studio
LABEL_STUDIO_URL = 'http://localhost:8080'
API_KEY = 'your_api_key'
ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY)

# Function to create a unique ID
def generate_unique_id():
    return str(uuid.uuid4())

# Create annotations with unique IDs
label_studio_result_list = [{
    'id': generate_unique_id(), # Generate a unique ID for each result
    'type': 'rectanglelabels',
    'value': {
        'x': x, 'y': y, 'width': w, 'height': h,
        'rotation': 0,
        'rectanglelabels': [result.names[result.boxes.cls.cpu().numpy()[idx]]]
    },
    'to_name': 'image', 'from_name': 'label',
    'origin': 'manual',
    'original_width': result.orig_img.shape[1],
    'original_height': result.orig_img.shape[0]
}]

ls_result = {"result": label_studio_result_list, 'completed_by': 2}
project.create_annotation(task_id, **ls_result)

# Function to update annotations programmatically
def update_annotations(task_id):
    task = project.get_task(task_id)
    annotations = task['annotations']
    for annotation in annotations:
        annotation_id = annotation['id']
        project.update_annotation(annotation_id, annotation)

# Update annotations for the task
update_annotations(task_id)

```

The generate\_unique\_id function creates a unique ID for each annotation result.  
When creating the annotations, the generated unique ID is included in each result.  
The update\_annotations function retrieves the task, iterates through its annotations, and updates each annotation using the SDK. This triggers the backend to process the annotations and generate the necessary IDs.

Let me know if this helps!

---

<div class="post-metadata">

**Author:** ![Stella\_Schlotter](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/stella_schlotter/32/61_2.png) [@Stella\_Schlotter](https://community.labelstud.io/u/Stella_Schlotter)\
**Post date:** [May 31, 2024, 5:25pm UTC](https://community.labelstud.io/t/missing-result-id-in-annotations-created-with-the-sdk/223/3 "2024-05-31T17:25:21Z")

</div>

Thank you that helps. I made it work like you suggested.
