Skip to content

Instantly share code, notes, and snippets.

@AustinMaddox
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AustinMaddox/9371286 to your computer and use it in GitHub Desktop.
Save AustinMaddox/9371286 to your computer and use it in GitHub Desktop.
Reverse fitment lookup service PHP example. The WPS reverse fitment web service returns vehicle data given one particular WPS part number. The output format is JSON. Below is a full example of how to do this via PHP using cURL.
<?php error_reporting(E_ALL | E_STRICT); ?>
<!DOCTYPE html>
<html>
<head>
<title>Reverse fitment example</title>
</head>
<body>
<?php
// Parameters to send the web service program.
// Example: http://www.example.com/reverse_fitment_lookup_service_example.php?DEALER=###&PASSWORD=###&ITEM=2-b9es&OUTPUT=json
$vars = array(
'DEALER' => FILTER_SANITIZE_ENCODED, // Your wpsorders dealer number.
'PASSWORD' => FILTER_SANITIZE_ENCODED, // Your wpsorders admin account password.
'ITEM' => FILTER_SANITIZE_ENCODED, // WPS item number.
'OUTPUT' => FILTER_SANITIZE_ENCODED // 'json' is used in this example.
);
// Gets external variables and optionally filters them.
$filtered_vars = filter_input_array(INPUT_GET, $vars);
// Make the cURL request.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.wpswebservices.com/version2/wsFITR.pgm");
curl_setopt($ch, CURLOPT_POSTFIELDS, $filtered_vars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$curl_result = curl_exec($ch);
curl_close($ch);
// Decode the JSON string into stdObject.
$result_json = json_decode($curl_result);
// If the result is not valid JSON.
if ($result_json === NULL) {
echo $curl_result . "<br>" . PHP_EOL;
die('The result of the cURL could not decoded with json_decode().');
}
// Print the HTML to set up a table.
echo '<table border="1">' . PHP_EOL;
echo ' <thead>' . PHP_EOL;
echo ' <tr>' . PHP_EOL;
echo ' <th>MAKE</th><th>MODEL</th><th>YEAR</th>' . PHP_EOL;
echo ' </tr>' . PHP_EOL;
echo ' </thead>' . PHP_EOL;
echo ' <tbody>' . PHP_EOL;
// For each property in the response, do this:
foreach ($result_json as $makes_obj) {
echo ' <tr>' . PHP_EOL;
echo ' <td>' . $makes_obj->make_description . '</td>' . PHP_EOL;
echo ' <td>&nbsp;</td>' . PHP_EOL;
echo ' <td>&nbsp;</td>' . PHP_EOL;
echo ' </tr>' . PHP_EOL;
foreach ($makes_obj->models as $models_obj) {
echo ' <tr>' . PHP_EOL;
echo ' <td>&nbsp;</td>' . PHP_EOL;
echo ' <td>' . $models_obj->model_description . '</td>' . PHP_EOL;
echo ' <td>&nbsp;</td>' . PHP_EOL;
echo ' </tr>' . PHP_EOL;
foreach ($models_obj->years as $year) {
echo ' <tr>' . PHP_EOL;
echo ' <td>&nbsp;</td>' . PHP_EOL;
echo ' <td>&nbsp;</td>' . PHP_EOL;
echo ' <td>' . $year . '</td>' . PHP_EOL;
echo ' </tr>' . PHP_EOL;
}
}
}
// Print the closing HTML table tags.
echo ' </tbody>' . PHP_EOL;
echo '</table>' . PHP_EOL;
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment