Squidex
  • Welcome to Squidex
  • Getting Started
    • Squidex Cloud
    • Installation Instructions
      • Platforms
        • Install on Kubernetes
        • Install on AWS (Deprecated)
        • Install on AWS EC2 using Docker
        • Install on Azure
        • Install on Azure using ARM
        • Install on Google Cloud Platform (GCP)
        • Install on Docker
        • Install on Heroku
        • Install on IIS
        • Install on Render
        • Install on Vultr
      • Configuration
        • Deploying the Image Resizer Service
      • Troubleshooting and Support
        • Diagnose Runtime Issues
        • Restoring Deleted Apps
      • Install Identity (Deprecated)
      • External Identity Providers
        • Azure AD (OAuth) with Squidex
    • Contributing and Developing
      • Building
      • Developing
      • Extensions
        • Custom Rule Action
      • Contributing
      • Architecture
      • Translating
      • Squidex Docs Program
    • Roadmap
    • Quick Start Guides
      • Vue.js Blog with Squidex
      • React.js Blog with Squidex
      • Angular Blog with Squidex
  • Documentation
    • Introduction and Use Case
    • Concepts
      • Apps
      • Teams
      • Schemas
        • Field Rules
      • Content
        • Scheduled Publishing
      • Assets
        • Querying Assets
      • Localization
      • Migrations
      • Roles & Permissions
      • Rules
        • Publish an Event to Azure Queues using Rules
        • Populate Elasticsearch Index
      • Backups
      • Subscriptions
        • App Subscriptions v/s Team Subscriptions
      • Notifications
      • Dashboard
      • Workflows
    • Software Development Kits
      • TypeScript
      • .NET
        • Version v14 (and Earlier)
        • Version v15 (and Later)
      • PHP
      • Java
    • Developer Guides
      • API
        • Authentication
        • Postman
        • Queries
        • Assets
      • Automation Tools (CLI)
      • Scripting
        • Scripting Helper Methods
      • Embed Content
      • Custom Workflows
      • Custom Editors
      • Custom Sidebars
      • Preview Content
      • Rule Formatting
        • Simple
        • Script
        • Liquid
      • Tutorials
        • Building a Blog with Squidex and Next.js
  • Next
    • Squidex 3.0: API Compatibility
Powered by GitBook
On this page
  • Introduction
  • Install the SDK
  • Instantiate the SDK
  • Additional Configuration
  • Use the Client
  • Error Handling

Was this helpful?

  1. Documentation
  2. Software Development Kits

PHP

Software Development Kit for all PHP platforms

PreviousVersion v15 (and Later)NextJava

Last updated 1 year ago

Was this helpful?

Introduction

The SDK is mostly generated from the OpenAPI specification. You can read the API documentation here:.

This means that the API is fully covered, including all endpoints used by the frontend. You can also use the SDK to create and configure Apps, schemas and rules.

Use this SDK in your PHP application to integrate with Squidex CMS.

Install the SDK

The SDK is available on . You can install it with:

compose install @squidex/squidex

Composer is a dependency manager for PHP:

Instantiate the SDK

The SquidexClient is the main entry point for the SDK. It provides the properties for all endpoints.

You can instantiate the client using the following code snippet:

use Squidex\Client\Configuration;
use Squidex\Client\SquidexClient;

require_once __DIR__ . '/../vendor/autoload.php';

$config = new Configuration();
$config->setClientId('client-id');
$config->setClientSecret('client-secret');
$config->setAppName('my-app');
$config->setHost('https://cloud.squidex.io');

$client = new SquidexClient($config);

The host parameter is optional if you are using Squidex Cloud.

Additional Configuration

Timeout

Configure a timeout in seconds to cancel unresponsive requests.

$config = new Configuration();
...
$config->setTimeout(60.0);

The default timeout is 30 seconds.

Token Store

The SDK uses the client ID and the client secret to acquire a bearer token, and handles invalidation and expiration automatically. By default the token is stored inside the client and therefore a new token is acquired when the client is cleaned by the garbage collector. However, one can define where the token is stored.

$config = new Configuration();
...
$config->setTokenStore(new MyTokenStore());

Ignore Certificates

By default the certificates are validated. But for test environments it might be necessary to connect to instances with self signed certificates only. Therefore we have introduced an option to ignore the certificate chain:

$config = new Configuration();
...
$config->setIgnoreCertificates(true);

Use the Client

To use the client you have to use the correct property.

For example, to create a schema use the schemas property.

$id = uniqid();

$field = new UpsertSchemaFieldDto();
$field->setName('field1');
$field->setProperties(new StringFieldPropertiesDto());

$request = new CreateSchemaDto();
$request->setName("my-schema");
$request->setIsPublished(true);
$request->setFields([$field]);

$createdSchema = $this->client->schemas()->postSchema($request);

In order to work with contents, use the contents property.

$data = [
    'field1' => [
        'iv' => 'My Value'
    ]
];
    
$createdContent = $this->client->contents()->postContent(static::$schema->getName(), $data);

Error Handling

The SDK uses exceptions for error handling.

Refer to the code snippet below for an example:

try {
    $request = new CreateAppDto();
    $request->setName('my-app');

    $client->getClient()->apps()->postApp($request);
} catch (ApiException $e) {
    if ($e->getCode() == 400) {
        echo "App probably already exists.\n";
    } else {
        throw $e;
    }
}

In this article, we will cover some of the important configuration values only. Have a look at the source code for all available options:

https://cloud.squidex.io/api/docs
packagist (compose)
https://getcomposer.org/
https://github.com/Squidex/sdk-php/blob/main/lib/Configuration.php