Installation Add the package via Composer (though note the read-only warning):
composer require beloop/squarespace-bundle
Register the bundle in config/bundles.php:
return [
// ...
Beloop\SquarespaceBundle\BeloopSquarespaceBundle::class => ['all' => true],
];
Configuration
Locate the default config in config/packages/beloop_squarespace.yaml (if auto-generated) or manually define:
beloop_squarespace:
api_key: '%env(SQUARESPACE_API_KEY)%'
base_url: 'https://api.squarespace.com/1.0'
First Use Case
Inject the SquarespaceClient service and fetch a site’s content:
use Beloop\SquarespaceBundle\Client\SquarespaceClient;
class MyController extends AbstractController {
public function __construct(private SquarespaceClient $client) {}
public function index() {
$siteId = 'YOUR_SITE_ID';
$response = $this->client->get('/sites/{$siteId}/content');
return $this->json($response);
}
}
API Integration
SquarespaceClient to interact with Squarespace’s REST API. Wrap calls in a service layer for reusability:
class SquarespaceService {
public function __construct(private SquarespaceClient $client) {}
public function fetchSiteContent(string $siteId): array {
return $this->client->get("/sites/{$siteId}/content");
}
}
Event-Driven Updates
$lastUpdated = Cache::get('squarespace_last_sync');
$changes = $this->client->get("/sites/{$siteId}/content?updated_after={$lastUpdated}");
// Process changes...
Cache::put('squarespace_last_sync', time());
Model Mapping
class SquarespaceContentMapper {
public function map(array $apiData): Content {
return Content::create([
'title' => $apiData['title'],
'url' => $apiData['url'],
'squarespace_id' => $apiData['id'],
]);
}
}
Authentication
.env and use dependency injection:
# config/services.yaml
services:
Beloop\SquarespaceBundle\Client\SquarespaceClient:
arguments:
$apiKey: '%env(SQUARESPACE_API_KEY)%'
Read-Only Warning
Deprecated API
/1.0). Verify compatibility with current docs.Error Handling
$this->client->setHandlerStack(
HandlerStack::create([
new RetryMiddleware(),
new \GuzzleHttp\HandlerStack::create(),
])
);
Configuration Overrides
config/services.yaml if needed.Logging
$this->client->setLogger(new \Monolog\Logger('squarespace'));
Testing
SquarespaceClient in tests:
$mock = $this->createMock(SquarespaceClient::class);
$mock->method('get')->willReturn(['data' => 'test']);
$this->app->instance(SquarespaceClient::class, $mock);
Extending
class CachedSquarespaceClient extends SquarespaceClient {
public function get($url) {
$cacheKey = "squarespace_{$url}";
return Cache::remember($cacheKey, 3600, fn() => parent::get($url));
}
}
Rate Limits
Webhooks
How can I help you explore Laravel packages today?