Getting errors that Models are not found

Uncaught Error: Class 'Models\SearchLoyaltyAccountsRequest' not found... in the browser. Is the error I get when I try and call $body = new Models\SearchLoyaltyAccountsRequest;

This is what I have at the top of my PHP file:

require __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

use Square\SquareClient;
use Square\LocationsApi;
use Square\Exceptions\ApiException;
use Square\Http\ApiResponse;
use Square\Models\ListLocationsResponse;
use Square\Environment;

$client = new SquareClient([
  'accessToken' => $_ENV['SQUARE_ACCESS_TOKEN'],
  'environment' => Environment::SANDBOX,

$loyaltyApi = $client->getLoyaltyApi();

If I change use Square\Models\ListLocationsResponse; to use Square\Models; The error goes away and my app finishes with the correct result. What am I missing?

Hey @toddsantoro welcome to the forums!

If you’re wanting to use SearchLoyaltyAccountsRequest, you should add a line at the top for use Square\Models\SearchLoyaltyAccountsRequest instead of Square\Models\ListLocationsResponse. Let me know if that doesn’t work, or if you have additional questions.

I actually thought that would work too and it did not. I even added use Square\LoyaltyApi; and I still get the error.

What version of the PHP SDK are you using? This worked for me:

use Square\Models\SearchLoyaltyAccountsRequest;
$body = new SearchLoyaltyAccountsRequest();
// or this $body = new \Square\Models\SearchLoyaltyAccountsRequest();

It might be because you didn’t have \Square\ in front of \Models? That produces an error for me, if I leave off Square.

That was the issue… Thanks!!!

1 Like