Basic curl bot post command in PHP

432 views
Skip to first unread message

Michael Wigle

unread,
Sep 13, 2016, 11:08:38 AM9/13/16
to GroupMe API Support
I'm not very familiar with curl but am able to manually type the curl command for posting as my bot (curl -d '{"text" : "Your message here", "bot_id" : "BOT_ID"}' https://api.groupme.com/v3/bots/post). However, I don't know how to launch that command in PHP. I know I need to use curl_exec() but don't know exactly how that translates. Can anyone give me a quick PHP example that would run the above command using curl_exec()?
Message has been deleted

Michael Wigle

unread,
Sep 13, 2016, 1:10:16 PM9/13/16
to GroupMe API Support
Looks like I found my answer. However, I'm using PHP5 instead of any curl code. It seems a little cleaner to me... Here's the PHP code that appears to do the job (BOT_ID is obviously your bot's ID):

<?php
$data = array('text' => Your message here', 'bot_id' => 'BOT_ID');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);
?>


On Tuesday, September 13, 2016 at 11:08:38 AM UTC-4, Michael Wigle wrote:
I'm not very familiar with curl but am able to manually type the curl command for posting as my bot (curl -d '{"text" : "Your message here", "bot_id" : "BOT_ID"}' https://api.groupme.com/v3/bots/post). However, I don't know how to launch that command in PHP. I know I need to use curl_exec() but don't know exactly how that translates. Can anyone give me a quick PHP example that would run the above command using curl_exec()?

Reply all
Reply to author
Forward
0 new messages