Skip to main content
POST
/
2
/
chat
/
media
/
upload
/
{id}
/
finalize
Finalize Chat Media Upload
curl --request POST \
  --url https://api.x.com/2/chat/media/upload/{id}/finalize \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "conversation_id": "<string>",
  "media_hash_key": "<string>",
  "message_id": "<string>",
  "num_parts": "<string>",
  "ttl_msec": "<string>"
}
'
import requests

url = "https://api.x.com/2/chat/media/upload/{id}/finalize"

payload = {
"conversation_id": "<string>",
"media_hash_key": "<string>",
"message_id": "<string>",
"num_parts": "<string>",
"ttl_msec": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
conversation_id: '<string>',
media_hash_key: '<string>',
message_id: '<string>',
num_parts: '<string>',
ttl_msec: '<string>'
})
};

fetch('https://api.x.com/2/chat/media/upload/{id}/finalize', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.x.com/2/chat/media/upload/{id}/finalize",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'conversation_id' => '<string>',
'media_hash_key' => '<string>',
'message_id' => '<string>',
'num_parts' => '<string>',
'ttl_msec' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

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

func main() {

url := "https://api.x.com/2/chat/media/upload/{id}/finalize"

payload := strings.NewReader("{\n \"conversation_id\": \"<string>\",\n \"media_hash_key\": \"<string>\",\n \"message_id\": \"<string>\",\n \"num_parts\": \"<string>\",\n \"ttl_msec\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.x.com/2/chat/media/upload/{id}/finalize")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"conversation_id\": \"<string>\",\n \"media_hash_key\": \"<string>\",\n \"message_id\": \"<string>\",\n \"num_parts\": \"<string>\",\n \"ttl_msec\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.x.com/2/chat/media/upload/{id}/finalize")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"conversation_id\": \"<string>\",\n \"media_hash_key\": \"<string>\",\n \"message_id\": \"<string>\",\n \"num_parts\": \"<string>\",\n \"ttl_msec\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "data": {
    "success": true
  }
}
{
"code": 123,
"message": "<string>"
}

Authorizations

Authorization
string
header
required

The access token received from the authorization server in the OAuth 2.0 flow.

Path Parameters

id
string
required

The session/resume id from initialize.

Body

application/json

Request body for finalizing a Chat media upload.

conversation_id
string

XChat conversation identifier for the upload.

media_hash_key
string

Media hash key returned from initialize.

message_id
string

Optional message identifier associated with the upload.

num_parts
string

Total number of uploaded parts as a numeric string.

ttl_msec
string

Optional TTL for the media in milliseconds.

Response

The request has succeeded.

Response from finalizing a Chat media upload.

data
object