# Update message status

PUT https://services.leadconnectorhq.com/conversations/messages/{messageId}/status

Post the necessary fields for the API to update message status.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `conversations/message.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `messageId` | string | Yes | Message Id |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/conversations/messages/{messageId}/status": {
      "put": {
        "summary": "Update message status",
        "operationId": "updateMessageStatus",
        "description": "Post the necessary fields for the API to update message status.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "messageId",
            "required": true,
            "in": "path",
            "description": "Message Id",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateMessageStatusDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created the message",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendMessageResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ForbiddenDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "conversations/message.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "UpdateMessageStatusDto": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "Message status",
            "example": "read",
            "enum": [
              "delivered",
              "failed",
              "pending",
              "read"
            ]
          },
          "error": {
            "description": "Error object from the conversation provider",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Error Code",
                    "example": "1"
                  },
                  "type": {
                    "type": "string",
                    "description": "Error Type",
                    "example": "saas"
                  },
                  "message": {
                    "type": "string",
                    "description": "Error Message",
                    "example": "There was an error from the provider"
                  }
                },
                "required": [
                  "code",
                  "type",
                  "message"
                ],
                "title": "ErrorDto"
              }
            ]
          },
          "emailMessageId": {
            "type": "string",
            "description": "Email message Id",
            "example": "ve9EPM428h8vShlRW1KT"
          },
          "recipients": {
            "description": "Email delivery status for additional email recipients.",
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "status"
        ],
        "title": "UpdateMessageStatusDto"
      },
      "SendMessageResponseDto": {
        "type": "object",
        "properties": {
          "conversationId": {
            "type": "string",
            "description": "Conversation ID.",
            "example": "ABC12h2F6uBrIkfXYazb"
          },
          "emailMessageId": {
            "type": "string",
            "description": "This contains the email message id (only for Email type). Use this ID to send inbound replies to CRM to create a threaded email.",
            "example": "rnGyqh2F6uBrIkfhFo9A"
          },
          "messageId": {
            "type": "string",
            "description": "This is the main Message ID",
            "example": "t22c6DQcTDf3MjRhwf77"
          },
          "messageIds": {
            "description": "When sending via the GMB channel, we will be returning list of `messageIds` instead of single `messageId`.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "msg": {
            "type": "string",
            "description": "Additional response message when sending a workflow message",
            "example": "Message queued successfully."
          }
        },
        "required": [
          "conversationId",
          "messageId"
        ],
        "title": "SendMessageResponseDto"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "ForbiddenDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 403
          },
          "message": {
            "type": "string",
            "example": "You do not have permission to access this resource"
          },
          "error": {
            "type": "string",
            "example": "Forbidden"
          }
        },
        "title": "ForbiddenDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X PUT 'https://services.leadconnectorhq.com/conversations/messages/<messageId>/status' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "status": "read",
  "error": {
    "code": "1",
    "type": "saas",
    "message": "There was an error from the provider"
  },
  "emailMessageId": "ve9EPM428h8vShlRW1KT",
  "recipients": []
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "status": "read",
      "error": {
        "code": "1",
        "type": "saas",
        "message": "There was an error from the provider"
      },
      "emailMessageId": "ve9EPM428h8vShlRW1KT",
      "recipients": []
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/conversations/messages/<messageId>/status', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/conversations/messages/{messageId}/status"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "status": "read",
    "error": {
        "code": "1",
        "type": "saas",
        "message": "There was an error from the provider"
    },
    "emailMessageId": "ve9EPM428h8vShlRW1KT",
    "recipients": []
}

response = requests.put(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/conversations/messages/<messageId>/status',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "status": "read",
  "error": {
    "code": "1",
    "type": "saas",
    "message": "There was an error from the provider"
  },
  "emailMessageId": "ve9EPM428h8vShlRW1KT",
  "recipients": []
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/conversations/messages/<messageId>/status")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"status\":\"read\",\"error\":{\"code\":\"1\",\"type\":\"saas\",\"message\":\"There was an error from the provider\"},\"emailMessageId\":\"ve9EPM428h8vShlRW1KT\",\"recipients\":[]}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/conversations/messages/<messageId>/status"
  payload := strings.NewReader(`{
  "status": "read",
  "error": {
    "code": "1",
    "type": "saas",
    "message": "There was an error from the provider"
  },
  "emailMessageId": "ve9EPM428h8vShlRW1KT",
  "recipients": []
}`)
  req, _ := http.NewRequest("PUT", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/conversations/messages/<messageId>/status")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "status": "read",
  "error": {
    "code": "1",
    "type": "saas",
    "message": "There was an error from the provider"
  },
  "emailMessageId": "ve9EPM428h8vShlRW1KT",
  "recipients": []
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "status": "read",
  "error": {
    "code": "1",
    "type": "saas",
    "message": "There was an error from the provider"
  },
  "emailMessageId": "ve9EPM428h8vShlRW1KT",
  "recipients": []
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/conversations/messages/<messageId>/status' -Method 'PUT' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
