
# Service Event Subscription


[Link to swagger documentation](https://service-subscription-settings.sandbox.infra.metro-markets.cloud/openapi/v1/api-doc)

The `service event subscription` allows you to be notified when you have a new order, or its status has changed (e.g, return requested, canceled, etc).

IMPORTANT: your server needs to reply with `http status code 200` and the following body:

```
{ "status":"OK"}
```

1. [How to subscribe to an event](#1-how-to-subscribe-to-an-event)
2. [How to get a list of all your subscribed events](#2-how-to-get-a-list-of-all-your-subscribed-events)
3. [How to change an event](#3-how-to-change-an-event)
4. [How to delete an event](#4-how-to-delete-an-event)
5. [List of events](#5-list-of-events)
   
   - [Orderline created](#orderline-created)
   - [Orderline shipped](#orderline-shipped)
   - [Orderline canceled](#orderline-canceled)
   - [Chat status updated](#chat-status-updated)
   - [Message created](#message-created)
6. [Error Handling](#6-error-handling)

### 1. How to subscribe to an event

You need to send a `POST` request to `/openapi/v1/subscriptions` indicating the event you would like to subscribe to.

In the body you need to specify:

- `url`: string - link to valid url where you would like to receive the notifications
- `event`: string containing the event. List of events [here](#5-list-of-events).
- `fallbackEmail`: e-Mail where you would receive the notifications in case there are any problems with your url
- `isActive`: boolean value

*Note: If you change API Keys, you will need to subscribe to the event again.*

Request example:

Endpoint: `http://service-subscription-settings.sandbox.infra.metro-markets.cloud/openapi/v1/subscriptions`  
Body:

```
{
  "url": "https://webhook.site/3e0a34ed-4429-4ae8-bcf1-7b6333635da7",
  "event": "order_created",
  "fallbackEmail": "3e0a34ed-4429-4ae8-bcf1-7b6333635da7@email.webhook.site",
  "isActive": true
}
```

Response:

```
{
    "id": "c396bfde-5f5c-43a9-ac15-54111b36f31e",
    "message": "Success. Subscription for \"events.names.order_created\" event is active."
}
```

You can do your tests using any opensource solution like [https://webhook.site/](https://webhook.site/). You need to set up the response as following:

![](/images/uploads/webhook_response.png#center)

When subscribing to and / or changing an event (`POST` , `PATCH`) we will send you a notification via webhooks to ensure that the connection is stablished.  
This message contains `x-signature`, `x-client` and `x-timestamp` in the headers and the following body:

```
{
  "messageId": "<uuid4>",
  "event": "test_connection",
  "payload": {
    "foo": "bar"
  }
}
```

### 2. How to get a list of all your subscribed events

You can use `GET /openapi/v1/subscriptions` to get a full list of all your events you are subscribed to.

Example: `http://service-subscription-settings.sandbox.infra.metro-markets.cloud/openapi/v1/subscriptions`  
Response:

```
[
    {
        "id": "c396bfde-5f5c-43a9-ac15-54111b36f31e",
        "url": "https://webhook.site/3e0a34ed-4429-4ae8-bcf1-7b6333635da7",
        "event": "order_created",
        "fallbackEmail": "3e0a34ed-4429-4ae8-bcf1-7b6333635da7@email.webhook.site",
        "isActive": true
    },
    {
        "id": "da8fb1a5-0d45-4e21-9c75-632f959a8eed",
        "url": "https://webhook.site/3e0a34ed-4429-4ae8-bcf1-7b6333635da7",
        "event": "order_line_cancelled",
        "fallbackEmail": "3e0a34ed-4429-4ae8-bcf1-7b6333635da7@email.webhook.site",
        "isActive": true
    }
]
```

### 3. How to change an event

To modify a subscription event, you can send a `PATCH` request with the `subscriptionId` and indicating the new values in the body to `/openapi/v1/subscriptions/{subscriptionId}`.

Example of how to change the url and the e-mail.

Endpoint: `http://service-subscription-settings.sandbox.infra.metro-markets.cloud/openapi/v1/subscriptions/c396bfde-5f5c-43a9-ac15-54111b36f31e`

Request body:

```
{
  "url": "https://webhook.site/e8faca72-fe0a-49ca-ab4c-3ba967bf7c83",
  "fallbackEmail": "e8faca72-fe0a-49ca-ab4c-3ba967bf7c83@email.webhook.site",
  "isActive": true
}
```

\**All fields are optional, but at least one needs to be in the body of the request.*

Response is status code 202 with the following body:

```
{
    "message": "Subscription successfully updated."
}
```

### 4. How to delete an event

If you want to delete an event you need to send a `DELETE` request to `/openapi/v1/subscriptions/{subscriptionId}` indicating the `subscriptionId`.

Example  
Request: `http://service-subscription-settings.sandbox.infra.metro-markets.cloud/openapi/v1/subscriptions/c396bfde-5f5c-43a9-ac15-54111b36f31e`

Response is `https status code 202` with the following body:

```
{
    "message": "Success. Subscription for \"events.names.order_created\" event is deactivated."
}
```

### 5. List of events

- [Orderline created](#orderline-created)
- [Orderline shipped](#orderline-shipped)
- [Orderline canceled](#orderline-canceled)
- [Chat status updated](#chat-status-updated)
- [Message created](#message-created)

#### Orderline created

It triggers when an order (orderline) is placed.

Event: `order_created`

Payload Schema

```
{
  "messageId": "<uniq_message_id>",
  "event": "order_created",
  "payload": {
    "orderId": "<uuid4>",
    "orderNumber": "O21-370758965005", < !--orderNumber is dynamic-->
    "organizationId": "<uuid4>",   
    "status": 1,                       < !--static value-->
    "createdAt": "<date-rfc-3339>"
  }
}
```

#### Orderline shipped

It triggers when a seller ships the orderline.  
This event triggers only when the action is done in Seller Office and not via API. This is to update data on Seller’s ERP system, via API http status code 204 is provided.

Event: `order_line_shipped`

Payload Schema

```
{
  "messageId": "<uniq_message_id>",
  "event": "order_line_shipped",
  "payload": {
    "orderLineId": "<uuid4>",
    "trackings": [
      {
        "trackingId": "<string|null>",
        "carrier": "<enum:dhl|feedex|null>",
        "customCarrier": "<string|null>",
        "country": "<string>"
      }
    ],
    "statusChanged": true
  },
  "emittedAt": "<date-rfc-3339>"
}
```

Note: `carrier` is the carrier defined in our dictionary. If `carrier` is provided, `customCarrier` is `null` and vice versa.

#### Orderline canceled

It triggers when a Buyer, a METRO Markets Employee or Seller (you) cancel/s an orderline.

Event: `order_line_canceled`

Payload Schema

```
{
    "messageId": "<uniq_message_id>",
    "event": "order_line_canceled",
    "emittedAt": "<date-rfc-3339>",
    "payload": {
        "orderLineId": "<uuid4>",
        "cancellationReason": <enum:1|2>
    }
}
```

Note: `cancellationReason` can be found [here](/docs/order/ordermanagement.md#how-to-get-all-possible-values-of-cancellation-reasons). If it´s `null`, no reason has been given.

* * *

#### Chat status updated

It triggers when the status of a Chat changes.

Event: `chat_status_updated`

The updated Chat can be retrieved using [Retrieve a Chat](/docs/message-center/chats.md#retrieve-a-chat) with the `chatId` from the payload.

Payload example:

```json
{
  "messageId": "fd4f0736-d6c0-442b-90ee-212435662fe2",
  "event": "chat_status_updated",
  "payload": {
    "chatId": "01a0c41e-d322-71f0-ad01-e65a10442c3e",
    "oldStatus": "DRAFT",
    "newStatus": "WAITING_FOR_SELLER",
    "changedAt": "2026-09-21T13:19:10+00:00",
    "changedByUserType": "BUYER",
    "triggeredBy": {
      "type": "MESSAGE",
      "id": "01a0c41e-d6c0-71ad-87e2-a41dd6878251"
    }
  },
  "emittedAt": "2026-09-21T13:19:10+00:00"
}
```

The `triggeredBy` object identifies what caused the status change:

- **Message-triggered:** `type` is `MESSAGE` and `id` is the ID of the Message that changed the Chat status. For example, a Chat can change from `DRAFT` to `WAITING_FOR_SELLER` when a Buyer initiates a Chat and sends a Message.
- **User-triggered:** `type` is `USER` and `id` matches the Chat’s `buyer.id` or `seller.accounts.id` of the User who changed the Chat status. For example, a Buyer can manually change a Chat from `WAITING_FOR_BUYER` to `CLOSED`.
- **System-triggered:** `type` is `SYSTEM` and no `id` is provided. For example, the system can change a Chat from `WAITING_FOR_SELLER` to `OVER_SLA`.

#### Message created

It triggers when a new Message is created in a Chat.

Event: `message_created`

The created Message can be retrieved using [Retrieve a Message](/docs/message-center/messages.md#retrieve-a-message) with the `chatId` and `messageId` from the payload.

Payload example:

```json
{
  "messageId": "d4eb7b42-4556-4570-bd31-bd17effbff5e",
  "event": "message_created",
  "payload": {
    "chatId": "01a0c41e-d322-71f0-ad01-e65a10442c3e",
    "messageId": "01a0c41e-d6c0-71ad-87e2-a41dd6878251",
    "hasAttachments": false,
    "createdAt": "2026-09-21T13:19:10+00:00"
  },
  "emittedAt": "2026-09-21T13:19:10+00:00"
}
```

* * *

### 6. Error Handling

#### Authorization error

Response `status code 401`.  
Response body:

```
{
  "type": "authorization",
  "title": "Authorization error",
  "status": 401,
  "detail": {
    "errors": [
      "Authentication openAPI key was not found"
    ]
  }
}
```

#### Not found error

Response `status code 404`.  
Response body:

```
{
  "type": "about:blank",
  "title": "Subscription not found",
  "status": 404,
  "detail": ""
}
```

#### URL doesn’t have correct response

Response `status code 412`.  
Response body:

```
{
  "type": "about:blank",
  "title": "Validation error",
  "status": 412,
  "detail": "Validation error",
  "instance": null,
  "invalidParams": [
    {
      "name": "url",
      "reason": "Server response is not valid"
    }
  ]
}
```

#### Validation error

Response `status code 412`.  
Response body:

```
{
    "type": "about:blank",
    "title": "Validation error",
    "status": 412,
    "detail": "",
    "instance": null,
    "invalidParams": [
        {
            "name": "limit",
            "reason": "This value is not valid."
        },
        {
            "name": "limit",
            "reason": "This value should be greater than 0."
        }
    ]
}
```
