API examples.
  • Hi everyone. I am working on a PHP based set of scripts to call in to the A911 API, and pull events out to populate a table for Incident forms, and response forms in a department. I am working through the examples here:


    But am really struggling with a practical example of how I tie the authorization code and token examples together into a script, as the authorization code example doesn't actually produce any output. Any assistance or practical info would be much appreciated. 

    Thanks,
    Richard.

  • <?php
    if((time()-filetime('access_token.txt')) > 86000)
    {
    $data=array('refresh_token'=>'<YOUR REFRESH TOKEN HERE>');
    $postString=http_build_query($data,'','&');
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$postString);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $response=curl_exec($ch);
    curl_close($ch);

    file_put_contents('access_token.txt',$response) or die('unable to save token');

    $access_token=json_decode($response,true);
    $access_token=$access_token['access_token'];
    }
    else
    {
    $access_token=file_get_contents('access_token.txt');
    $access_token=json_decode($access_token,true);
    $access_token=$access_token['access_token'];
    }

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type: application/json',"Authorization: Bearer $access_token"));
    curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    $result=curl_exec($ch);
    curl_close($ch);

    $alert_array=json_decode($contents,true);

    print_r($alert_array);

    ?>