The following function is an example showing how to add a group id to the json payload to send to yammer.
function postMessage($token_, $message_, $group_id_) {
$result_ = array() ;
$result_['token'] = $token_ ;
$result_['message'] = $message_ ;
$associativeArray = true ;
$payloadArray_ = array() ;
$payloadArray_['body'] = $message_ ;
if ( $group_id_ > 0 ) {
$payloadArray_['group_id'] = $group_id_ ;
}
try {
$curl_ = curl_init() ;
$headers = array() ;
$headers[] = "Authorization: Bearer " . $token_ ;
$headers[]='Content-Type: application/json' ;
$url = 'https://www.yammer.com/api/v1/messages.json' ;
curl_setopt($curl_, CURLOPT_URL, $url);
curl_setopt($curl_, CURLOPT_POST, true);
curl_setopt($curl_, CURLOPT_POSTFIELDS, json_encode( $payloadArray_));
curl_setopt($curl_, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl_);
$result_['response'] = json_decode($response,$associativeArray) ;
} catch ( Exception $exception ) {
error_log ( $exception->getMessage() ) ;
$result_['exception'] = $exception->getMessage() ;
}
return $result_ ;
}