Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
composer.lock
.phpunit.cache/
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Change Log

## 31.0.0

* Breaking: requests send `X-Appwrite-Response-Format: 2.5.0`; responses follow the 2.5 shapes
* Breaking: removed `Account::listLogs`, `Users::listLogs` and the `Log`/`LogList` models
* Breaking: removed `Organization::createKey`, `getKey`, `listKeys`, `updateKey` and `deleteKey`, and `OrganizationKeyScopes`; use `Organization::listProjectKeys`, `getProjectKey`, `updateProjectKey` and `deleteProjectKey` instead
* Breaking: removed `Client::setDevKey`, the `DevKey` model and `Project::$devKeys`
* Breaking: removed `BillingPlanGroup::STARTER()`; use `BillingPlanGroup::FREE()`
* Breaking: `listSpecifications` returns each specification's prices and overage rates on the row itself. Removed the list-level `$pricing` field and the `DedicatedDatabaseSpecificationPricing` model
* Breaking: removed `Block` fields `reason`, `projectName`, `region`, `organizationName`, `organizationId` and `billingPlan`
* Breaking: OAuth2 `resource` params now take `?array`
* Breaking: `Project::updateOAuth2Kakao` takes `$enabled` before `$prompt`
* Breaking: `BackupRestoration::$options` is now an array
* Breaking: some response fields became nullable, such as `BillingPlan::$usage` and `DedicatedDatabase::$engine`
* Breaking: the protected `Client::flatten` is renamed `flattenForm`; subclasses that override it must rename it
* Added: `Topic` helper to build MQTT topics for push messages
* Added: `Mongo`, `Mysql` and `Postgresql` `promoteRestoration`, `$restoreMode`, `$targetName` and `$autoPromote` on `createRestoration`, and `DedicatedDatabaseRestoration::$restoreMode`
* Added: `Proxy::createSMTPRule`, the `ProxyRuleProtocol` enum and `ProxyRule::$protocol`
* Added: `$emailEnabled` on `Functions::update` and `FunctionModel`, and `ExecutionTrigger::EMAIL()`
* Added: `Query` aggregates (`count`, `countDistinct`, `sum`, `avg`, `min`, `max` and more), `groupBy`, `having`, `distinct`, joins, `relationship`, `covers`, `spatialEquals` and `page`
* Added: `Query::builder()` to chain queries; `build()` returns the query list
* Fixed: OAuth2 models wrap a single `prompt` value in a list

## 30.4.0

* Added: `domains` service to manage domains, DNS records, email presets, prices, transfer status and zones
Expand Down
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Appwrite PHP SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-php.svg?style=flat-square&v=1)
![Version](https://img.shields.io/badge/api%20version-2.0.0-blue.svg?style=flat-square&v=1)
![Version](https://img.shields.io/badge/api%20version-2.5.0-blue.svg?style=flat-square&v=1)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK targets Appwrite server version 1.9.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-php/releases) when APIs differ.
**This SDK targets Appwrite server version 2.5.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-php/releases) when APIs differ.

Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the PHP SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

Expand All @@ -22,6 +22,33 @@ composer require appwrite/appwrite

Requires PHP 8.5 or later.

### Custom HTTP transport

For applications that configure their own HTTP transport, pass any PSR-18 client to the constructor. Hosts that run SDK calls concurrently, such as Swoole coroutines, should pass a pooled client so no cURL handle is shared between coroutines:

```php
use Appwrite\Client;
use Utopia\Client\Adapter\SwooleCoroutine\Client as SwooleAdapter;
use Utopia\Client\Client as HttpClient;
use Utopia\Client\Pool as PooledClient;
use Utopia\Pools\Adapter\Swoole as SwoolePool;
use Utopia\Pools\Pool;

$client = new Client(new PooledClient(new Pool(
new SwoolePool(),
'appwrite',
128,
fn (): HttpClient => new HttpClient(new SwooleAdapter())
->withConnectionReuse()
->withTimeout(5)
->withConnectTimeout(2),
timeout: 3.0,
)));
$client->setEndpoint('https://cloud.appwrite.io/v1');
```

Configure timeouts, TLS, redirects, and connection reuse on the injected transport. The SDK's `setTimeout()`, `setConnectTimeout()`, and `setSelfSigned()` methods only configure the default cURL transport. Endpoint, authentication, headers, request encoding, and response handling remain the SDK's responsibility. A transport used with `responseType: 'location'` must have redirect following disabled.


## Getting Started

Expand Down Expand Up @@ -76,7 +103,7 @@ $users = new Users($client);
try {
$user = $users->create(ID::unique(), "email@example.com", "+123456789", "password", "Walter O'Brien");
} catch(AppwriteException $error) {
echo $error->message;
echo $error->getMessage();
}

```
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"php": ">=8.5",
"ext-curl": "*",
"ext-json": "*",
"psr/http-client": "^1.0",
"utopia-php/client": "^0.6",
"adhocore/jwt": "^1.1"
},
Expand Down
22 changes: 5 additions & 17 deletions docs/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ DELETE https://cloud.appwrite.io/v1/account/identities/{identityId}
| identityId | string | **Required** Identity ID. | |


```http request
GET https://cloud.appwrite.io/v1/account/logs
```

** Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log. **

### Parameters

| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset | [] |
| total | boolean | When set to false, the total count returned will be 0 and will not be calculated. | 1 |


```http request
PATCH https://cloud.appwrite.io/v1/account/mfa
```
Expand Down Expand Up @@ -591,7 +577,7 @@ GET https://cloud.appwrite.io/v1/account/sessions
DELETE https://cloud.appwrite.io/v1/account/sessions
```

** Delete all sessions from the user account and remove any sessions cookies from the end client. **
** Delete all sessions from the user account and remove any sessions cookies from the end client. Pass `current` as false to keep the session making the request and sign out of every other session. **

### Parameters

Expand All @@ -611,7 +597,7 @@ POST https://cloud.appwrite.io/v1/account/sessions/anonymous
POST https://cloud.appwrite.io/v1/account/sessions/email
```

** Allow the user to login into their account by providing a valid email and password combination. This route will create a new session for the user.
** Allow the user to login into their account by providing a valid email and password combination. This route will create a new session for the user. Use the optional `duration` parameter to create a shorter session, for example when the user doesn't choose "remember me". It must be at least 60 seconds and cannot exceed the project maximum session length.

A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). **

Expand Down Expand Up @@ -786,13 +772,15 @@ GET https://cloud.appwrite.io/v1/account/tokens/oauth2/{provider}

If authentication succeeds, `userId` and `secret` of a token will be appended to the success URL as query parameters. These can be used to create a new session using the [Create session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint.

If there is already an active session, the OAuth2 identity is attached to the logged-in account and that session stays active until the token is exchanged for a new one.

A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). **

### Parameters

| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| provider | string | **Required** OAuth2 Provider. Currently, supported providers are: amazon, apple, appwrite, auth0, authentik, autodesk, bitbucket, bitly, box, cloudflare, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, fusionauth, github, gitlab, google, huggingface, keycloak, kick, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, resend, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, x, yahoo, yammer, yandex, zoho, zoom. | |
| provider | string | **Required** OAuth2 Provider. Currently, supported providers are: amazon, apple, appwrite, auth0, authentik, autodesk, bitbucket, bitly, box, cloudflare, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, fusionauth, github, gitlab, google, huggingface, kakao, keycloak, kick, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, resend, salesforce, slack, spotify, stripe, tiktok, tradeshift, tradeshiftBox, twitch, webflow, wordpress, x, yahoo, yammer, yandex, zoho, zoom. | |
| success | string | URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. | |
| failure | string | URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. | |
| scopes | array | A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. | [] |
Expand Down
2 changes: 1 addition & 1 deletion docs/apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ PUT https://cloud.appwrite.io/v1/apps/{appId}/labels
| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| appId | string | **Required** Application unique ID. | |
| labels | array | Array of application labels. Replaces the previous labels. Maximum of 1000 labels are allowed, each up to 36 alphanumeric characters long. | |
| labels | array | Array of application labels. Replaces the previous labels. Maximum of 1000 labels are allowed, each up to 36 alphanumeric characters long. Reserved labels are rejected. | |


```http request
Expand Down
4 changes: 2 additions & 2 deletions docs/avatars.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ When one dimension is specified and the other is 0, the image is scaled with pre
GET https://cloud.appwrite.io/v1/avatars/photo
```

** Returns the best available profile photo for a user. The endpoint tries each source in priority order and returns the first successful result: OAuth2 identity photo, Gravatar, Libravatar, Appwrite Initials, built-in static fallback.
** Returns the best available profile photo for a user. The endpoint tries each source in priority order and returns the first successful result: a custom uploaded photo (see avatars.updatePhoto), OAuth2 identity photo, Gravatar, Libravatar, Appwrite Initials, built-in static fallback.

Passing `userId` — `current()` for the authenticated user — resolves the photo from everything known about that user: identity photos, email, and name. An explicit `emailHash` or `name` then overrides just that value, and the user's remaining sources stay in the chain. Without `userId`, passing `emailHash` and/or `name` resolves the avatar from those values alone: the hash is looked up on Gravatar and Libravatar, the name is rendered as initials, and the session user stays out of the chain so their own photo never shadows the avatar being asked for. When nothing is passed, the photo resolves for the currently authenticated user. Emails are only ever accepted pre-hashed, so no address ends up in a URL. **

Expand Down Expand Up @@ -186,7 +186,7 @@ When width and height are specified, the image is resized accordingly. If both d
| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| url | string | **Required** Website URL which you want to capture. | |
| headers | object | HTTP headers to send with the browser request. Defaults to empty. | {} |
| headers | object | HTTP headers to send with the browser request. Only Accept and Accept-Language are allowed. Defaults to empty. | {} |
| viewportWidth | integer | Browser viewport width. Pass an integer between 1 to 1920. Defaults to 1280. | 1280 |
| viewportHeight | integer | Browser viewport height. Pass an integer between 1 to 1080. Defaults to 720. | 720 |
| scale | number | Browser scale factor. Pass a number between 0.1 to 3. Defaults to 1. | 1 |
Expand Down
4 changes: 2 additions & 2 deletions docs/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ POST https://cloud.appwrite.io/v1/databases/{databaseId}/collections
| documentSecurity | boolean | Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions). | |
| enabled | boolean | Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled. | 1 |
| attributes | array | Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, double, boolean, datetime, point, linestring, polygon, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options. | [] |
| indexes | array | Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional). | [] |
| indexes | array | Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial, trigram), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional). | [] |


```http request
Expand Down Expand Up @@ -1210,7 +1210,7 @@ POST https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collection
```

** Creates an index on the attributes listed. Your index should include all the attributes you will query in a single request.
Attributes can be `key`, `fulltext`, and `unique`. **
Attributes can be `key`, `fulltext`, `unique`, `spatial`, and `trigram`. `trigram` is only available on PostgreSQL and lets `contains`, `startsWith`, and `endsWith` queries on string attributes use an index. **

### Parameters

Expand Down
2 changes: 1 addition & 1 deletion docs/documentsdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ POST https://cloud.appwrite.io/v1/documentsdb
GET https://cloud.appwrite.io/v1/documentsdb/specifications
```

** List the dedicated database specifications available on the current plan. Each specification reports its resource limits, pricing, and whether it is enabled for the organization. **
** List the dedicated database specifications available on the current plan. Each specification reports its resource limits, its own prices and overage rates, and whether it is enabled for the organization. **


```http request
Expand Down
18 changes: 0 additions & 18 deletions docs/examples/account/list-logs.md

This file was deleted.

3 changes: 1 addition & 2 deletions docs/examples/avatars/get-screenshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ $avatars = new Avatars($client);
$result = $avatars->getScreenshot(
url: 'https://example.com',
headers: [
'Authorization' => 'Bearer token123',
'X-Custom-Header' => 'value'
'Accept-Language' => 'en-US,en;q=0.9'
], // optional
viewportWidth: 1920, // optional
viewportHeight: 1080, // optional
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/databases/create-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $result = $databases->createDocument(
data: [
'username' => 'walter.obrien',
'email' => 'walter.obrien@example.com',
'fullName' => 'Walter O'Brien',
'fullName' => 'Walter O\'Brien',
'age' => 30,
'isAdmin' => false
],
Expand Down
11 changes: 10 additions & 1 deletion docs/examples/databases/create-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ $databases = new Databases($client);
$result = $databases->createDocuments(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documents: [],
documents: [
[
'$id' => 'example1',
'username' => 'walter.obrien',
'email' => 'walter.obrien@example.com',
'fullName' => 'Walter O\'Brien',
'age' => 30,
'isAdmin' => false
]
],
transactionId: '<TRANSACTION_ID>' // optional
);
```
5 changes: 4 additions & 1 deletion docs/examples/databases/create-enum-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ $result = $databases->createEnumAttribute(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
key: '<KEY>',
elements: ["active", "inactive"],
elements: [
'active',
'inactive'
],
required: false,
default: 'active', // optional
array: false // optional
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/databases/create-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ $result = $databases->createIndex(
collectionId: '<COLLECTION_ID>',
key: '<KEY>',
type: DatabasesIndexType::KEY(),
attributes: [],
attributes: [
'username'
],
orders: [OrderBy::ASC()], // optional
lengths: [] // optional
);
Expand Down
15 changes: 14 additions & 1 deletion docs/examples/databases/create-line-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ $result = $databases->createLineAttribute(
collectionId: '<COLLECTION_ID>',
key: '<KEY>',
required: false,
default: [[1, 2], [3, 4], [5, 6]] // optional
default: [
[
1,
2
],
[
3,
4
],
[
5,
6
]
] // optional
);
```
20 changes: 10 additions & 10 deletions docs/examples/databases/create-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ $databases = new Databases($client);
$result = $databases->createOperations(
transactionId: '<TRANSACTION_ID>',
operations: [
{
"action": "create",
"databaseId": "<DATABASE_ID>",
"collectionId": "<COLLECTION_ID>",
"documentId": "<DOCUMENT_ID>",
"data": {
"name": "Walter O'Brien"
}
}
] // optional
[
'action' => 'create',
'databaseId' => '<DATABASE_ID>',
'collectionId' => '<COLLECTION_ID>',
'documentId' => '<DOCUMENT_ID>',
'data' => [
'name' => 'Walter O\'Brien'
]
]
] // optional
);
```
5 changes: 4 additions & 1 deletion docs/examples/databases/create-point-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ $result = $databases->createPointAttribute(
collectionId: '<COLLECTION_ID>',
key: '<KEY>',
required: false,
default: [1, 2] // optional
default: [
1,
2
] // optional
);
```
Loading