Skip to main content
This guide builds on the C# SDK setup, which covers install and authentication.

Workflow to post media tweets and DM attachments

Use this workflow to post a media tweet or reply. It can also DM an uploaded local file. client.X.Tweets.Create maps to POST /x/tweets. Pass public media URLs through Media. Send up to 4 image URLs or exactly 1 MP4 video URL. The video can be up to 100 MB. Do not mix video with other media. For replies, set ReplyToTweetID to the parent tweet ID. client.X.Media.Upload maps to POST /x/media. Use media.MediaID only for the one-item MediaIds handoff on client.X.Dm.Send.
Use client.X.Tweets.WithRawResponse.Create to capture the durable write action. Send a unique Idempotency-Key. Store id, request.hash, billing, result, and statusUrl. Poll while terminal is false. Retry only when safeToRetry is true, using a new key. Keep DM body text in private systems. Shared logs and handoffs should store message_id, optional media_id, account, user_id, and lifecycle status. Leave ReplyToMessageID unset because the REST endpoint rejects DM reply threading. client.X.Dm.DeleteMessage deletes a DM. Use public media URLs with client.X.Tweets.Create. Do not pass uploaded media.MediaID values to tweet creation.

REST routes

Next steps