-
Notifications
You must be signed in to change notification settings - Fork 1
API call notebook
Mark S Howe edited this page Apr 3, 2018
·
4 revisions
Example calls to the Fish Fry API
API docs at http://fishfry.codeforpgh.com/apidocs/
use this to set publish
and validated
properties to false
, to get help the map ready for next year
curl ...
Example
$id = 'c3d08926-d218-464a-a62c-46a13d14bcb1'
$content = '{"id":"c3d08926-d218-464a-a62c-46a13d14bcb1","type":"Feature","properties":{"etc":"MON-SAT 9 AM - 7 PM\r\nSUN 9 AM - 6 PM","homemade_pierogies":true,"handicap":true,"events":[{"dt_end":"2018-02-16T19:00:00","dt_start":"2018-02-16T09:00:00"},{"dt_end":"2018-02-23T19:00:00","dt_start":"2018-02-23T09:00:00"},{"dt_end":"2018-03-02T19:00:00","dt_start":"2018-03-02T09:00:00"},{"dt_end":"2018-03-09T19:00:00","dt_start":"2018-03-09T09:00:00"},{"dt_end":"2018-03-16T19:00:00","dt_start":"2018-03-16T09:00:00"},{"dt_end":"2018-03-23T19:00:00","dt_start":"2018-03-23T09:00:00"},{"dt_end":"2018-03-30T19:00:00","dt_start":"2018-03-30T09:00:00"}],"venue_notes":null,"alcohol":null,"website":"http:\/\/www.mcginnis-sisters.com\/","venue_name":"McGinnis Sisters","venue_type":"Market","venue_address":"4311 Northern Pike, Monroeville, PA","menu":{"text":null,"url":null},"publish":false,"lunch":true,"email":null,"phone":"412-858-7000","take_out":true,"validated":false},"geometry":{"coordinates":[-79.753389,40.435043],"type":"Point"}}'
$headers = array("accept: application/json", "content-type: application/json", 'Content-Length: ' . strlen($content));
$url = 'http://fishfry.codeforpgh.com/api/fishfry/?' . $id;
print $url . "<BR>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
//curl_setopt($ch, CURLOPT_TRANSFERTEXT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
////curl_setopt($ch, CURLPROTO_FTPS,1);
print_r($ch);
print "<BR> Before sending <BR>";
$rc = curl_exec($ch);
print_r(curl_getinfo($ch));
print "<BR> results <BR>";
print $rc . " After sending <BR>";
curl_close($ch);
Update field code
ini_set("allow_url_fopen", TRUE);
ini_set("allow_url_include", TRUE);
$filename = 'http://fishfry.codeforpgh.com/api/fishfries/';
// Read JSON file
$json = file_get_contents($filename);
//Decode JSON
$json_data = json_decode($json, true);
for ($i = 0; $i < sizeof($json_data['features']); $i++) {
//$features = $json_data['features'][$i];
$VENUE_ID = $json_data['features'][$i]['id'];
$json_data['features'][$i]['properties']['publish'] = false;
$json_data['features'][$i]['properties']['validated'] = false;
$features = json_encode($json_data['features'][$i]);
//$geometry = "'" . json_encode($json_data['features'][$i]['geometry']) . "'";
$contents = $features ;
print $VENUE_ID . "<BR>";
print $contents . "<BR>";
//call to curl code
}