Skip to content

Commit a047caa

Browse files
committed
Upgraded to support Appwrite 0.8
1 parent 8b2693a commit a047caa

40 files changed

+1101
-44
lines changed

README.md

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Appwrite PHP SDK
22

3-
![License](https://img.shields.io/github/license/appwrite/sdk-for-php.svg?v=1)
4-
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?v=1)
3+
![License](https://img.shields.io/github/license/appwrite/sdk-for-php.svg?style=flat-square&v=1)
4+
![Version](https://img.shields.io/badge/api%20version-0.8.0-blue.svg?style=flat-square&v=1)
5+
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
6+
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
57

6-
**This SDK is compatible with Appwrite server version 0.7.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-php/releases).**
8+
**This SDK is compatible with Appwrite server version 0.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-php/releases).**
79

810
Appwrite is an open-source backend as a service server that abstract and simplify 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.
911
Use the PHP SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools.
@@ -19,6 +21,72 @@ To install via [Composer](http://getcomposer.org/):
1921
composer require appwrite/appwrite
2022
```
2123

24+
25+
## Getting Started
26+
27+
### Init your SDK
28+
Initialize your SDK code with your project ID which can be found in your project settings page and your new API secret Key from project's API keys section.
29+
30+
```php
31+
$client = new Client();
32+
33+
$client
34+
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
35+
->setProject('5df5acd0d48c2') // Your project ID
36+
->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
37+
->setSelfSigned() // Use only on dev mode with a self-signed SSL cert
38+
;
39+
```
40+
41+
### Make Your First Request
42+
Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.
43+
44+
```php
45+
$users = new Users($client);
46+
47+
$result = $users->create('[email protected]', 'password');
48+
```
49+
50+
### Full Example
51+
```php
52+
use Appwrite\Client;
53+
use Appwrite\Services\Users;
54+
55+
$client = new Client();
56+
57+
$client
58+
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
59+
->setProject('5df5acd0d48c2') // Your project ID
60+
->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
61+
->setSelfSigned() // Use only on dev mode with a self-signed SSL cert
62+
;
63+
64+
$users = new Users($client);
65+
66+
$result = $users->create('[email protected]', 'password');
67+
```
68+
69+
### Error Handling
70+
The Appwrite PHP SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
71+
72+
```php
73+
$users = new Users($client);
74+
try {
75+
$result = $users->create('[email protected]', 'password');
76+
} catch(AppwriteException $error) {
77+
echo $error->message;
78+
}
79+
80+
```
81+
82+
### Learn more
83+
You can use followng resources to learn more and get help
84+
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server)
85+
- 📜 [Appwrite Docs](https://appwrite.io/docs)
86+
- 💬 [Discord Community](https://appwrite.io/discord)
87+
- 🚂 [Appwrite PHP Playground](https://github.com/appwrite/playground-for-php)
88+
89+
2290
## Contribution
2391

2492
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

docs/account.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Account Service
2+
3+
## Get Account
4+
5+
```http request
6+
GET https://appwrite.io/v1/account
7+
```
8+
9+
** Get currently logged in user data as JSON object. **
10+
11+
## Delete Account
12+
13+
```http request
14+
DELETE https://appwrite.io/v1/account
15+
```
16+
17+
** Delete a currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. This is done to avoid deleted accounts being overtaken by new users with the same email address. Any user-related resources like documents or storage files should be deleted separately. **
18+
19+
## Update Account Email
20+
21+
```http request
22+
PATCH https://appwrite.io/v1/account/email
23+
```
24+
25+
** Update currently logged in user account email address. After changing user address, user confirmation status is being reset and a new confirmation mail is sent. For security measures, user password is required to complete this request.
26+
This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password. **
27+
28+
### Parameters
29+
30+
| Field Name | Type | Description | Default |
31+
| --- | --- | --- | --- |
32+
| email | string | User email. | |
33+
| password | string | User password. Must be between 6 to 32 chars. | |
34+
35+
## Get Account Logs
36+
37+
```http request
38+
GET https://appwrite.io/v1/account/logs
39+
```
40+
41+
** Get currently logged in user list of latest security activity logs. Each log returns user IP address, location and date and time of log. **
42+
43+
## Update Account Name
44+
45+
```http request
46+
PATCH https://appwrite.io/v1/account/name
47+
```
48+
49+
** Update currently logged in user account name. **
50+
51+
### Parameters
52+
53+
| Field Name | Type | Description | Default |
54+
| --- | --- | --- | --- |
55+
| name | string | User name. Max length: 128 chars. | |
56+
57+
## Update Account Password
58+
59+
```http request
60+
PATCH https://appwrite.io/v1/account/password
61+
```
62+
63+
** Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth and Team Invites, oldPassword is optional. **
64+
65+
### Parameters
66+
67+
| Field Name | Type | Description | Default |
68+
| --- | --- | --- | --- |
69+
| password | string | New user password. Must be between 6 to 32 chars. | |
70+
| oldPassword | string | Old user password. Must be between 6 to 32 chars. | |
71+
72+
## Get Account Preferences
73+
74+
```http request
75+
GET https://appwrite.io/v1/account/prefs
76+
```
77+
78+
** Get currently logged in user preferences as a key-value object. **
79+
80+
## Update Account Preferences
81+
82+
```http request
83+
PATCH https://appwrite.io/v1/account/prefs
84+
```
85+
86+
** Update currently logged in user account preferences. You can pass only the specific settings you wish to update. **
87+
88+
### Parameters
89+
90+
| Field Name | Type | Description | Default |
91+
| --- | --- | --- | --- |
92+
| prefs | object | Prefs key-value JSON object. | |
93+
94+
## Create Password Recovery
95+
96+
```http request
97+
POST https://appwrite.io/v1/account/recovery
98+
```
99+
100+
** Sends the user an email with a temporary secret key for password reset. When the user clicks the confirmation link he is redirected back to your app password reset URL with the secret key and email address values attached to the URL query string. Use the query string params to submit a request to the [PUT /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to complete the process. The verification link sent to the user's email address is valid for 1 hour. **
101+
102+
### Parameters
103+
104+
| Field Name | Type | Description | Default |
105+
| --- | --- | --- | --- |
106+
| email | string | User email. | |
107+
| url | string | URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project 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. | |
108+
109+
## Complete Password Recovery
110+
111+
```http request
112+
PUT https://appwrite.io/v1/account/recovery
113+
```
114+
115+
** Use this endpoint to complete the user account password reset. Both the **userId** and **secret** arguments will be passed as query parameters to the redirect URL you have provided when sending your request to the [POST /account/recovery](/docs/client/account#accountCreateRecovery) endpoint.
116+
117+
Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface. **
118+
119+
### Parameters
120+
121+
| Field Name | Type | Description | Default |
122+
| --- | --- | --- | --- |
123+
| userId | string | User account UID address. | |
124+
| secret | string | Valid reset token. | |
125+
| password | string | New password. Must be between 6 to 32 chars. | |
126+
| passwordAgain | string | New password again. Must be between 6 to 32 chars. | |
127+
128+
## Get Account Sessions
129+
130+
```http request
131+
GET https://appwrite.io/v1/account/sessions
132+
```
133+
134+
** Get currently logged in user list of active sessions across different devices. **
135+
136+
## Delete All Account Sessions
137+
138+
```http request
139+
DELETE https://appwrite.io/v1/account/sessions
140+
```
141+
142+
** Delete all sessions from the user account and remove any sessions cookies from the end client. **
143+
144+
## Delete Account Session
145+
146+
```http request
147+
DELETE https://appwrite.io/v1/account/sessions/{sessionId}
148+
```
149+
150+
** Use this endpoint to log out the currently logged in user from all their account sessions across all of their different devices. When using the option id argument, only the session unique ID provider will be deleted. **
151+
152+
### Parameters
153+
154+
| Field Name | Type | Description | Default |
155+
| --- | --- | --- | --- |
156+
| sessionId | string | **Required** Session unique ID. Use the string 'current' to delete the current device session. | |
157+
158+
## Create Email Verification
159+
160+
```http request
161+
POST https://appwrite.io/v1/account/verification
162+
```
163+
164+
** Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#accountUpdateVerification). The verification link sent to the user's email address is valid for 7 days.
165+
166+
Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
167+
**
168+
169+
### Parameters
170+
171+
| Field Name | Type | Description | Default |
172+
| --- | --- | --- | --- |
173+
| url | string | URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project 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. | |
174+
175+
## Complete Email Verification
176+
177+
```http request
178+
PUT https://appwrite.io/v1/account/verification
179+
```
180+
181+
** Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code. **
182+
183+
### Parameters
184+
185+
| Field Name | Type | Description | Default |
186+
| --- | --- | --- | --- |
187+
| userId | string | User unique ID. | |
188+
| secret | string | Valid verification token. | |
189+

docs/database.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ PUT https://appwrite.io/v1/database/collections/{collectionId}
6262
| --- | --- | --- | --- |
6363
| collectionId | string | **Required** Collection unique ID. | |
6464
| name | string | Collection name. Max length: 128 chars. | |
65-
| read | array | An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions(/docs/permissions) and get a full list of available permissions. | |
66-
| write | array | An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
65+
| read | array | An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
66+
| write | array | An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
6767
| rules | array | Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation. | [] |
6868

6969
## Delete Collection
@@ -115,8 +115,8 @@ POST https://appwrite.io/v1/database/collections/{collectionId}/documents
115115
| --- | --- | --- | --- |
116116
| collectionId | string | **Required** Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). | |
117117
| data | object | Document data as JSON object. | |
118-
| read | array | An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
119-
| write | array | An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
118+
| read | array | An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
119+
| write | array | An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
120120
| parentDocument | string | Parent document unique ID. Use when you want your new document to be a child of a parent document. | |
121121
| parentProperty | string | Parent document property name. Use when you want your new document to be a child of a parent document. | |
122122
| parentPropertyType | string | Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document. | assign |
@@ -151,8 +151,8 @@ PATCH https://appwrite.io/v1/database/collections/{collectionId}/documents/{docu
151151
| collectionId | string | **Required** Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection). | |
152152
| documentId | string | **Required** Document unique ID. | |
153153
| data | object | Document data as JSON object. | |
154-
| read | array | An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
155-
| write | array | An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
154+
| read | array | An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
155+
| write | array | An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions. | |
156156

157157
## Delete Document
158158

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Account;
5+
6+
$client = new Client();
7+
8+
$client
9+
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
10+
->setProject('5df5acd0d48c2') // Your project ID
11+
->setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token
12+
;
13+
14+
$account = new Account($client);
15+
16+
$result = $account->createRecovery('[email protected]', 'https://example.com');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Account;
5+
6+
$client = new Client();
7+
8+
$client
9+
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
10+
->setProject('5df5acd0d48c2') // Your project ID
11+
->setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token
12+
;
13+
14+
$account = new Account($client);
15+
16+
$result = $account->createVerification('https://example.com');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Account;
5+
6+
$client = new Client();
7+
8+
$client
9+
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
10+
->setProject('5df5acd0d48c2') // Your project ID
11+
->setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token
12+
;
13+
14+
$account = new Account($client);
15+
16+
$result = $account->deleteSession('[SESSION_ID]');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Account;
5+
6+
$client = new Client();
7+
8+
$client
9+
->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
10+
->setProject('5df5acd0d48c2') // Your project ID
11+
->setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token
12+
;
13+
14+
$account = new Account($client);
15+
16+
$result = $account->deleteSessions();

0 commit comments

Comments
 (0)