Hey.Café Help   ›   Developer Resources   ›   Examples   ›   Simple PHP API requests

Simple PHP API requests

This is a simple function to make API requests. You can provide no post variables, or any variables that are needed in the API call.

You can learn more about each API call that takes advantage of the API keys at https://endpoint.hey.cafe.

function heycafe_request($key,$call,$post=false){
    $ch = curl_init("https://endpoint.hey.cafe/".$call."?auth=".$key."");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)');
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 7);
    if ($post!=false){
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

$post = [
    'content_raw' => 'Hello world'
];

$data=heycafe_request("YOURAPIKEY","post_conversation_create",$post);