How to send direct messages from the api?



I’m trying this way, following the documentation on the official twitter page

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);

$data = [
    'event' => [
        'type' => 'message_create',
        'message_create' => [
            'target' => [
                'recipient_id' => 'xxxxxx'
            'message_data' => [
                'text' => 'Hello World!'

$content = $connection->post("direct_messages/events/new",['content-type: application/json' => $data]);

can someone please give me a little guidance please.

I do not get any error message, I can not see an answer


It looks like you might be using TwitterOAuth in which case you are not calling post quite right.

$content = $connection->post("direct_messages/events/new", $data, true);


Thank you, Mr. Abraham.
yes I do, I’m using the TwitterAOuth library for php.
I have done as I indicated and it has worked, thank you very much for your help. :slight_smile: :man_technologist:t4:
Have a good day.