How to use Twitter API v1.1 to send a direct message with an image.

You would upload the image first, using Attaching media | Docs | Twitter Developer Platform

And then DM as usual, but with the media ID in an attachment json object: POST direct_messages/events/new (message_create) | Docs | Twitter Developer Platform

But I am getting this error

If you are calling STATUS and getting an error did the previous calls to INIT, APPEND, FINALIZE all work?

Generally, I would not recommend making these calls in Postman, there is a better, more complete example here: large-video-upload-python/async-upload.py at master · twitterdev/large-video-upload-python · GitHub in python however.

INIT – > it’s working fine

APPEND – > It’s working fine.

1 Like

FINALIZE – > I am getting this error

1 Like

@IgorBrigadir So, what should I do?

There are some other mistakes here: It looks like you are passing a URL to an image to media_type when calling INIT - this is incorrect, it should me a MIME type like image/jpeg

APPEND is also receiving fake data, so likely won’t work, even though the HTTP request is correct. It should be the actual bytes of the image file, not a URL.

FINALIZE is failing because there is no valid image uploaded in the previous steps. Or it could actually be something else wrong with the parameters, either way - Postman is difficult to use here.

What are the steps for testing INIT in Postman?
Is there a Body on this API?

This is the endpoint: POST media/upload (INIT) | Docs | Twitter Developer Platform (and the others are there too)

Requests should be either multipart/form-data or application/x-www-form-urlencoded POST formats.

But why go through all this in the first place? Ideally, when implementing this in code, your library should handle these steps.

Postman is good for debugging individual calls, but there’s usually no need to do these steps manually or debug these media upload steps if you don’t have an implementation in a programming language. I would use Postman for debugging a specific error where normal code fails, otherwise, for learning how to use the API it’s probably easier to implement it in code as opposed to trying to use Postman.