codeartistgirl codeartistgirl - 1 year ago 103
PHP Question

How can I get my Square Connect location without using command line

I want to start by saying I have searched extensively, including google,, and Stack Overflow and cannot find an answer to my question. I have posed this question to Square support, and (even though I mentioned I could not access command line and have already done the tutorial mentioned below, I was directed to said tutorial and told to use the command line that I can't use. Here's my problem...

I am trying to set up the square connect API on a webserver for a client. On the webserver, I do not have access to command line (or SSH without an additional cost to the client). The only ways I have found to get the location_id requires command line (as far as I can tell). Is there a way to not have to use command line? Or is there another way to put in the required command without command line access?

Here is what I have done so far:

I read somewhere (can't remember where now) that you can install composer locally, use command line on your machine to install the dependencies needed for square-connect, then move all the files to your server. I have done that to get the files on the server.

My file structure looks like this:

The locations-test.php contains:

require 'vendor/autoload.php';
$access_token = "ACCESS_TOKEN";
$location_api = new \SquareConnect\Api\LocationApi();
echo $location_api->listLocations($access_token);

Note: ACCESS_TOKEN has been replaced with my personal access token.

Of coarse, if I access this file at, I get a blank page.

Also, I am not getting any errors in the error log.

The way to get locations is lined out here.
Under "Retrieving your location IDs." I am OK up until this point, but I cannot use command line in my server to use the code:

php locations-test.php

What are my other options to get the location_id? What am I missing?

Thanks in advance for any help or direction!

Answer Source

According the php-sdk you're using for connecting to the square API, the required format for $access_token should be "Bearer YOUR_ACCESS_TOKEN" no just your access token.

 * @param string $authorization The value to provide in the Authorization header of
 * your request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.

Try using this instead and see if it works.

require 'vendor/autoload.php';
$access_token = "Bearer ACCESS_TOKEN";
$location_api = new \SquareConnect\Api\LocationApi();
echo $location_api->listLocations($access_token);

Of course, don't forget to replace the ACCESS_TOKEN part with your own access token.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download