# Service interactions and responses (/docs/guides/service-interactions)



> Hubtel sends each step of a customer's session to your Service Interaction URL. Reply with the next screen, end the session, or send the item to checkout.
Register your endpoint as described in [Programmable Services](/docs/guides/ussd#register). Field names and values are case-sensitive.

## Incoming request [#incoming-request]

| Field         | Type    | Meaning                                                                                                         |
| ------------- | ------- | --------------------------------------------------------------------------------------------------------------- |
| `Type`        | String  | `Initiation` starts a session, `Response` continues it, and `Timeout` means the customer cancelled the session. |
| `Message`     | String  | Customer input, or the dialled USSD string at initiation.                                                       |
| `ServiceCode` | String  | Service code, for example `711*2`.                                                                              |
| `Operator`    | String  | `mtn`, `vodafone` (Telecel), `tigo` or `airtel` (AirtelTigo).                                                   |
| `ClientState` | String  | The `ClientState` you returned in your last response. It's sent once, then discarded.                           |
| `Mobile`      | String  | Customer's phone number.                                                                                        |
| `SessionId`   | String  | Identifier for the current session.                                                                             |
| `Sequence`    | Integer | Position of this message in the session.                                                                        |
| `Platform`    | String  | `USSD`, `Webstore` or `Hubtel-App`.                                                                             |

```json
{
  "Type": "Initiation",
  "Mobile": "233249111411",
  "SessionId": "example-session",
  "ServiceCode": "713",
  "Message": "*713#",
  "Operator": "vodafone",
  "Sequence": 1,
  "ClientState": "",
  "Platform": "USSD"
}
```

## Return a response [#return-a-response]

| Field         | Required        | Meaning                                                                                                               |
| ------------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
| `SessionId`   | Yes             | Return the session identifier from the request.                                                                       |
| `Type`        | Yes             | `response` continues the session; `release` ends it; `AddToCart` ends the interaction and sends the item to checkout. |
| `Message`     | Yes             | USSD display text. Use `\n` for new lines and write menu choices in the text.                                         |
| `Mask`        | No              | Marks the current message as masked.                                                                                  |
| `Item`        | For `AddToCart` | Purchase object; leave empty for other response types.                                                                |
| `ServiceCode` | No              | Return the service code where needed.                                                                                 |
| `Label`       | Yes             | Title shown on app and web channels.                                                                                  |
| `DataType`    | Yes             | `display` for information or `input` for customer input.                                                              |
| `FieldType`   | Yes             | The input control: `text`, `phone`, `email`, `number` (whole numbers), `decimal` or `textarea`.                       |
| `Sequence`    | No              | Message position.                                                                                                     |
| `ClientState` | No              | State to return with the next request.                                                                                |

## Example session [#example-session]

Return a menu for the initiation request:

```json
{
  "SessionId": "example-session",
  "Type": "response",
  "Message": "Choose a service\n1. Buy airtime\n2. Check balance",
  "Label": "Choose a service",
  "ClientState": "menu",
  "DataType": "input",
  "FieldType": "text"
}
```

When the customer selects `1`, the next request has `Type: "Response"`, `Message: "1"`, `Sequence: 2` and `ClientState: "menu"`. Return a numeric input screen:

```json
{
  "SessionId": "example-session",
  "Type": "response",
  "Message": "Enter the airtime amount",
  "Label": "Airtime amount",
  "ClientState": "amount",
  "DataType": "input",
  "FieldType": "decimal"
}
```

Use `ClientState` to know which question the customer is answering. Validate input such as the amount before you build an item.

## Start payment with AddToCart [#start-payment-with-addtocart]

```json
{
  "SessionId": "example-session",
  "Type": "AddToCart",
  "Message": "Your request has been submitted. Follow the payment prompt to continue.",
  "Item": { "ItemName": "Airtime", "Qty": 1, "Price": 5.0 },
  "Label": "Complete payment",
  "DataType": "display",
  "FieldType": "text"
}
```

`AddToCart` ends the session and starts payment. It isn't proof of payment: wait for the paid order at your Service Fulfilment URL. See [Service fulfilment](/docs/guides/service-fulfilment).

## End a session and handle invalid responses [#end-a-session-and-handle-invalid-responses]

Return `Type: "release"` with the required fields to end a session without payment. A `Timeout` request means the customer left: don't create a purchase.

Don't use special characters such as `É` in `Message`. If customers see **"The response from the provider of this service is invalid. Error: UUE"**, your response body isn't in the expected format: check the required fields.
