HOME
List Square Locations

This standalone script connects to Square Locations API via cURL and returns existing locations on your account. This is helpful when the WooCommerce Square extension does not retrieve the locations, and web hosts claim that cURL is working as expected

<?php

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, 'https://connect.squareup.com/v2/locations' );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer PRODUCTION_ACCESS_TOKEN', 'Accept: application/json', 'Square-Version: 2021-04-21' ) );
curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

if ( curl_exec( $ch ) === false ) {
	echo 'Curl error: ' . curl_error( $ch );
} else {
	$data = json_decode( curl_exec( $ch ) );
	echo '<pre>';
	print_r( $data );
	echo '</pre>';
}

curl_close( $ch );

USAGE:

This is not a WordPress plugin, so please upload this script to the root directory of the site and access it directly: https://example.com/square-list-locations.php

For Production environment:

The square production access token

For Sandbox environment:

RESULTS:

If things work fine, you’ll see a list of Square locations and their details. If not, you’ll see the cURL error.

All cURL errors start with Curl error:. If you don’t see that, it means the error you’re seeing is returned by Square.

Source/Credits: https://developer.squareup.com/docs/locations-api

Leave a Reply

Your email address will not be published. Required fields are marked *