Square - Get Locations with PHP & CURL

Square - Get Locations with PHP & cUrl

Save this as a php file, for example, list-customers.php, then provide your access token, from your Square Apps.

 

<?php

$endpoint_host = 'connect.squareupsandbox.com/v2/';
$access_token = 'YOUR-ACCESS-TOKEN';
$idempotency_key = uniqid();
$verify_ssl = false; //Set false for localhost/unsigned SSLs, and true for production

$curl = curl_init();

curl_setopt_array($curl, array(
 CURLOPT_URL => $endpoint_host.'locations',
  CURLOPT_SSL_VERIFYHOST => $verify_ssl,
  CURLOPT_SSL_VERIFYPEER => $verify_ssl,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 60,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer '.$access_token

  ),

));


$response = curl_exec($curl);
  $err = curl_error($curl);
  $response = json_decode($response);
  curl_close($curl);
  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    var_dump($response);
  }

Share this Post