How to make a custom PHP cURL GET Request with Postman?

Hi guys! :slight_smile:

I’ve just downloaded Postman and learning to get started. It seems pretty straight-forward with making requests to REST API based servers, although I need to make a very specific PHP cURL request to another server in order to obtain an MD5 encoded hash key to authorize my request.

I’m sure that it’s just my understanding which is holding me back from being able to make a request like this through Postman, though I have successfully done it before using XAMPP.

Below is the PHP request which I need to make, as well as a few of the different endpoints available to fetch data from.

Does anyone know if this is possible with Postman? I’ve tried using the “Import → Paste Raw Text / Upload File” methods although it keeps saying the format is unrecognized.

This is the PHP cURL Request together with the MD5 Hash Generator to obtain a signature, by using the $key and $secret variables which need to be appended to the parameters of the endpoints called later on:

class OpenApiService{

public static function call($apiUrl, $secret, $parameters){
$signature = OpenApiService::sign($parameters, $secret);
$parameters[‘signature’] = $signature;
$postdata = http_build_query($parameters);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

public static function download($apiUrl, $secret, $parameters, $path){
$signature = OpenApiService::sign($parameters, $secret);
$parameters[‘signature’] = $signature;
$postdata = http_build_query($parameters);
$fp = fopen($path, ‘w’);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}

public static function sign($parameters, $secret){
$signature = ‘’;
ksort($parameters);
foreach($parameters as $key=>$value){
$signature .= $value;
}
$signature = $signature . ‘@’ . $secret;
$signature = md5($signature);
return $signature;
}
}
?>

These are the endpoints which can be called to fetch different sets of data, in this instance it makes use of the class created above called OpenAPIService in the $result variable to append the parameters & MD5 hash to the Endpoint.

// Fetch the details for the product
if(false){
$apiUrl = “http://www.example.com/openapi/product!detail.do”;
$parameters = array(
‘key’ => $key,
‘itemNo’ => ‘S-MPH-6016B’
);
$result = OpenApiService::call($apiUrl, $secret, $parameters);
echo $result;
}

// Download the images
if(true){
$apiUrl = “http://www.example.com/openapi/product!getImages.do”;
$parameters = array(
‘key’ => $key,
‘itemNo’ => ‘S-MPH-6016B’,
‘size’ => ‘50’,
‘watermark’ => ‘mysite.com
);
$path = ‘test.zip’;
OpenApiService::download($apiUrl, $secret, $parameters, $path);
}

// Fetch the countries and states
if(false){
$apiUrl = “http://www.example.com/openapi/order!getCountries.do”;
$parameters = array(
‘key’ => $key
);
$result = OpenApiService::call($apiUrl, $secret, $parameters);
echo $result;
}

// Calculate the prices and freights for the items
if(false){
$apiUrl = “http:/www.example.com/openapi/order!getPricesAndFreights.do”;
$parameters = array(
‘key’ => $key,
‘countryId’ => ‘41’,
‘items.1.itemNo’ => ‘S-IP4G-0363’,
‘items.1.qty’ => ‘20’,
‘items.2.itemNo’ => ‘S-MAC-0230’,
‘items.2.qty’ => ‘5’
);
$result = OpenApiService::call($apiUrl, $secret, $parameters);
echo $result;
}

The documentation also mentions the following: “The parameters should be sorted by the name before the signature generation.”

Additionally, if this type of request would be possible within Postman, how would you be able to fetch multiple pages worth of data in a single request (i.e loop through all of the ID’s present?)

I would really appreciate any and all assistance offered! :slight_smile:

Thank you.

Bump.

I’m hoping that someone could help out :slight_smile:

Bump.

Anyone, please?