Home > database >  How to use Postman environment variables inside PHP Curl?
How to use Postman environment variables inside PHP Curl?

Time:11-26

enter image description here

This is from POSTMAN. I am confused about how to use these Postman environment variables in PHP Curl.

"BearToken" : "abc416abc416abc416abc416abc416abc416"

"HostURL" : "https://app.flowtrack.co"

"public_key" : "dj0lZewEkMlFZg0yMaQP"

"private_key" : "VOqAv6JcKV3sGRxT8Rm1fgkCWQ32Mg"

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => '/api/contact',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "country": "US",
    "phone_country": "US",
    "first_name": "John",
    "last_name": "Test",
    "email": "[email protected]",
    "street": "Road 3",
    "city": "testing",
    "zip": "233334",
    "phone": " 17145757567",
    "dial_code": "1",
    "hasZip": true, 
    "hasState": true, 
    "company_id": "yep19k"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

CodePudding user response:

Issue solved-

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://app.flowtrack.co/api/contact?public_key=dj0lZewEkMlFZg0yMaQP&private_key=VOqAv6JcKV3sGRxT8Rm1fgkCWQ32Mg',
  CURLOPT_SSL_VERIFYHOST => 0,
  CURLOPT_SSL_VERIFYPEER => 0,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "country": "US",
    "phone_country": "US",
    "first_name": "John",
    "last_name": "Test",
    "email": "[email protected]",
    "street": "Road 3",
    "city": "testing",
    "zip": "233334",
    "phone": " 17145757567",
    "dial_code": "1",
    "hasZip": true, 
    "hasState": true, 
    "company_id": "yep19k"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
  • Related