# Annotations

## `/getImageAnnotations/<image_id>`

## Get the already stored annotations for an image

<mark style="color:blue;">`GET`</mark> `/getImageAnnotations/<image_id>`

Gets the annotations in a JSON format for Annotorious.&#x20;

#### Query Parameters

| Name                                    | Type   | Description     |
| --------------------------------------- | ------ | --------------- |
| \<id><mark style="color:red;">\*</mark> | String | Id of the image |

#### Headers

| Name                                             | Type   | Description |
| ------------------------------------------------ | ------ | ----------- |
| x-access-token<mark style="color:red;">\*</mark> | String | User token  |

{% tabs %}
{% tab title="200: OK JSON object with all the annotations" %}

```json
[
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Son": {
            "type": ["producer"],
            "volume": "0"
          },
          "Vue": {
            "sense": "Vue"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "jeux de Billards",
        "purpose": "transcription",
			},
		 	"creator": {
          "id": "id_user",
          "name": "user_name"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64..... OU mettre URL de l'image OU nom du fichier image (unique)",
      "selector": {
        "type": "FragmentSelector",
        "conformsTo": "http://www.w3.org/TR/media-frags/",
        "value": "xywh=pixel:324,174,411,106"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#a39cbd17-6d53-4c7b-8500-354f0dcb9cf4"
  },
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Vue": {
            "sense": "Vue"
          },
          "Son": {
            "type": [
              "producer"
            ],
            "volume": "42"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "vendeurs de café",
        "purpose": "transcription"
			}
 		"creator": {
          "id": "alefi-20-20",
          "name": "Alexis"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64....",
      "selector": {
        	"type": "SvgSelector",
        	"value": "<svg><polygon points=\"544,12 749,111 776,27\" /></svg>"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#6fefe9fc-2543-40ad-9c0f-3147c7f26af0"
  }
]
```

{% endtab %}

{% tab title="401: Unauthorized Token is missing or invalid" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## `/createAnnotation/<image_id>`

## Creates a new annotation

<mark style="color:green;">`POST`</mark> `/createAnnotation/<image_id>`

`Creates`

#### Query Parameters

| Name                                    | Type   | Description     |
| --------------------------------------- | ------ | --------------- |
| \<id><mark style="color:red;">\*</mark> | String | Id of the image |

#### Headers

| Name                                             | Type   | Description |
| ------------------------------------------------ | ------ | ----------- |
| x-access-token<mark style="color:red;">\*</mark> | String | User token  |

#### Request Body

| Name                                          | Type    | Description                                         |
| --------------------------------------------- | ------- | --------------------------------------------------- |
| body<mark style="color:red;">\*</mark>        | JSON    | Body of the annotation in the W3C Annotation format |
| zone\_type<mark style="color:red;">\*</mark>  | boolean | Type of the zone (false: rectangle, true: polygon)  |
| zone\_coord<mark style="color:red;">\*</mark> | String  | Coordinates of the annotation in the image          |

{% tabs %}
{% tab title="200: OK Annotation created" %}

```json
[
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Son": {
            "type": ["producer"],
            "volume": "0"
          },
          "Vue": {
            "sense": "Vue"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "jeux de Billards",
        "purpose": "transcription",
			},
		 	"creator": {
          "id": "id_user",
          "name": "user_name"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64..... OU mettre URL de l'image OU nom du fichier image (unique)",
      "selector": {
        "type": "FragmentSelector",
        "conformsTo": "http://www.w3.org/TR/media-frags/",
        "value": "xywh=pixel:324,174,411,106"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#a39cbd17-6d53-4c7b-8500-354f0dcb9cf4"
  },
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Vue": {
            "sense": "Vue"
          },
          "Son": {
            "type": [
              "producer"
            ],
            "volume": "42"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "vendeurs de café",
        "purpose": "transcription"
			}
 		"creator": {
          "id": "alefi-20-20",
          "name": "Alexis"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64....",
      "selector": {
        	"type": "SvgSelector",
        	"value": "<svg><polygon points=\"544,12 749,111 776,27\" /></svg>"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#6fefe9fc-2543-40ad-9c0f-3147c7f26af0"
  }
]
```

{% endtab %}

{% tab title="401: Unauthorized Token is missing or invalid" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## `/deleteAnnotation`

{% hint style="danger" %}
**This request requiere the user to be an editor.**
{% endhint %}

## Deletes

<mark style="color:blue;">`GET`</mark> `/deleteAnnotation`

Deletes&#x20;

#### Headers

| Name                                             | Type   | Description       |
| ------------------------------------------------ | ------ | ----------------- |
| x-access-token<mark style="color:red;">\*</mark> | String | Editor user token |

#### Request Body

| Name | Type   | Description              |
| ---- | ------ | ------------------------ |
| id   | String | annotation\_id to delete |

{% tabs %}
{% tab title="200: OK Annotation deleted" %}

```json
[
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Son": {
            "type": ["producer"],
            "volume": "0"
          },
          "Vue": {
            "sense": "Vue"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "jeux de Billards",
        "purpose": "transcription",
			},
		 	"creator": {
          "id": "id_user",
          "name": "user_name"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64..... OU mettre URL de l'image OU nom du fichier image (unique)",
      "selector": {
        "type": "FragmentSelector",
        "conformsTo": "http://www.w3.org/TR/media-frags/",
        "value": "xywh=pixel:324,174,411,106"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#a39cbd17-6d53-4c7b-8500-354f0dcb9cf4"
  },
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Vue": {
            "sense": "Vue"
          },
          "Son": {
            "type": [
              "producer"
            ],
            "volume": "42"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "vendeurs de café",
        "purpose": "transcription"
			}
 		"creator": {
          "id": "alefi-20-20",
          "name": "Alexis"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64....",
      "selector": {
        	"type": "SvgSelector",
        	"value": "<svg><polygon points=\"544,12 749,111 776,27\" /></svg>"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#6fefe9fc-2543-40ad-9c0f-3147c7f26af0"
  }
]
```

{% endtab %}

{% tab title="401: Unauthorized Token is missing or invalid" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="403: Forbidden User is not allowed to delete" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## `/updateAnnotationCoord`

{% hint style="danger" %}
**This request requiere the user to be an editor.**
{% endhint %}

## Update the coordinates in the image

<mark style="color:blue;">`GET`</mark> `/updateAnnotationCoord`

Update

#### Query Parameters

| Name                                    | Type   | Description     |
| --------------------------------------- | ------ | --------------- |
| \<id><mark style="color:red;">\*</mark> | String | Id of the image |

#### Headers

| Name                                             | Type   | Description |
| ------------------------------------------------ | ------ | ----------- |
| x-access-token<mark style="color:red;">\*</mark> | String | User token  |

#### Request Body

| Name                                          | Type   | Description                  |
| --------------------------------------------- | ------ | ---------------------------- |
| id<mark style="color:red;">\*</mark>          | String | annotation\_id to edit       |
| zone\_coord<mark style="color:red;">\*</mark> | String | New coordinates in the image |

{% tabs %}
{% tab title="200: OK JSON object with all the annotations" %}

```json
[
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Son": {
            "type": ["producer"],
            "volume": "0"
          },
          "Vue": {
            "sense": "Vue"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "jeux de Billards",
        "purpose": "transcription",
			},
		 	"creator": {
          "id": "id_user",
          "name": "user_name"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64..... OU mettre URL de l'image OU nom du fichier image (unique)",
      "selector": {
        "type": "FragmentSelector",
        "conformsTo": "http://www.w3.org/TR/media-frags/",
        "value": "xywh=pixel:324,174,411,106"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#a39cbd17-6d53-4c7b-8500-354f0dcb9cf4"
  },
  {
    "type": "Annotation",
    "body": [
      {
        "value": {
          "Vue": {
            "sense": "Vue"
          },
          "Son": {
            "type": [
              "producer"
            ],
            "volume": "42"
          }
        },
        "purpose": "sense"
      },
      {
        "value": "vendeurs de café",
        "purpose": "transcription"
			}
 		"creator": {
          "id": "alefi-20-20",
          "name": "Alexis"
        },
        "created": "2022-07-12T10:26:57.607Z"
      }
    ],
    "target": {
      "source": "data:image/jpeg;base64....",
      "selector": {
        	"type": "SvgSelector",
        	"value": "<svg><polygon points=\"544,12 749,111 776,27\" /></svg>"
      }
    },
    "@context": "http://www.w3.org/ns/anno.jsonld",
    "id": "#6fefe9fc-2543-40ad-9c0f-3147c7f26af0"
  }
]
```

{% endtab %}

{% tab title="401: Unauthorized Token is missing or invalid" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="403: Forbidden User is not allowed to edit" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}
