<?php // JSON filter to make API query results from zippopotam.us easy to include in Zingtree // call like this: // https://zingtree.com/apps/webhook/filters/zippopotamus.php?zip=94960 // see http://api.zippopotam.us $zip = htmlspecialchars($_REQUEST['zip']) ; // call zippopotamus with the ZIP passed along $url = "http://api.zippopotam.us/us/".rawurlencode($zip); // deepcode ignore PT: URL already sanitized and call required to get data $data = json_decode(file_get_contents ($url), true); // make the result object, and encode results as a simple JSON block $results['zip'] = $zip ; $results['state'] = $data['places'][0]['state'] ; $results['state_abbreviation'] = $data['places'][0]['state abbreviation'] ; $results['city'] = $data['places'][0]['place name'] ; header('Content-Type: application/json'); echo json_encode($results) ; exit ; ?>