You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-16Lines changed: 26 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,8 @@ $client = new ManagementApiClient($storyblokPersonalAccessToken);
91
91
92
92
The Storyblok **Management API Client** provides two main approaches for interacting with the API:
93
93
94
-
- Using specific API classes (like `StoryApi` or `SpaceApi` or `AssetApi` or `TagApi`)
94
+
- Using specific API classes (like `StoryApi` or `SpaceApi` or `AssetApi` or `TagApi` or `UserApi`)
95
+
- Using specific API classes for handling bulk data (like `StoryBulkApi`)
95
96
- Using the `ManagementApi` class
96
97
97
98
The `ManagementApi` class offers a flexible, generic interface for managing content. It includes methods to get, create, update, and delete content. With this approach, you can define the endpoint path and pass query string parameters as a generic array. The response is returned as a `StoryblokData` object, allowing you to access the JSON payload, status codes, and other details directly.
@@ -102,10 +103,11 @@ If a dedicated API class like `SpaceApi` or `StoryApi` does not exist for your d
102
103
103
104
In addition to the general-purpose `ManagementApi` class, the Storyblok Management PHP client also provides specific classes such as `SpaceApi`, `StoryApi`, `TagApi` and `AssetApi`. These classes function similarly to the `ManagementApi` but are tailored for specific scenarios, offering additional methods or data types to work with particular resources.
104
105
105
-
-**`SpaceApi`** focuses on managing space-level operations, such as retrieving space information, performing backup etc.
106
-
-**`StoryApi`** specializes in handling stories and their content, including creating, updating, retrieving, and deleting stories. This class also provides methods that deal with the structure and fields specific to stories.
107
-
-**`AssetApi`** designed to manage assets like images, files, and other media. It provides methods to upload, retrieve, and manage assets, offering features specific to media management.
108
-
-**`TagApi`** designed to manage tags.
106
+
-`SpaceApi` focuses on managing space-level operations, such as retrieving space information, performing backup etc.
107
+
-`StoryApi` specializes in handling stories and their content, including creating, updating, retrieving, and deleting stories. This class also provides methods that deal with the structure and fields specific to stories.
108
+
-`AssetApi` designed to manage assets like images, files, and other media. It provides methods to upload, retrieve, and manage assets, offering features specific to media management.
109
+
-`TagApi` designed to manage tags.
110
+
-`UserApi` designed to handle the current user. "Current" means the user related to the access token used for instancing the `ManagementApiClient` object.
109
111
110
112
These specialized classes extend the functionality of the `ManagementApi` class, offering more precise control and optimized methods for interacting with specific resource types in your Storyblok space.
To get the current user, owner of the Personal access token used you can use the userApi and the UserData.
392
+
To get the current user, owner of the Personal access token used you can use the `UserApi` class for calling endpoints and the `User` for accessing to returned data object properties.
393
+
For example, here we want to retrieve the current user (via the `me()` method) and obtaining the `User` object via `data()`.
391
394
392
395
```php
396
+
use Storyblok\ManagementApi\Endpoints\UserApi;
397
+
use Storyblok\ManagementApi\ManagementApiClient;
398
+
399
+
$client = new ManagementApiClient(getAccessToken());
393
400
394
-
$response = new UserApi($client)->me();
395
-
/** @var UserData $currentUser */
396
-
$currentUser = $response->data();
401
+
$currentUser = (new UserApi($client))->me()->data();
397
402
// "User ID"
398
-
echo $currentUser->id();
403
+
echo $currentUser->id() . PHP_EOL;
399
404
// "User identifier"
400
-
echo $currentUser->userid();
405
+
echo $currentUser->userid() . PHP_EOL;
401
406
// "User email"
402
-
echo $currentUser->email());
407
+
echo $currentUser->email() . PHP_EOL;
403
408
// "User has Organization"
404
-
echo $currentUser->hasOrganization() ? " HAS ORG" : "NO ORG";
405
-
// "User Organization"
406
-
echo $currentUser->orgName();
409
+
echo ($currentUser->hasOrganization() ? " HAS ORG:" . $currentUser->orgName() : "NO ORG") . PHP_EOL;
407
410
// "User has Partner"
408
-
echo $currentUser->hasPartner() ? " HAS PARTNER" : "NO PARTNER";
411
+
echo ($currentUser->hasPartner() ? " HAS PARTNER" : "NO PARTNER") . PHP_EOL;;
412
+
409
413
```
410
414
415
+
416
+
Typically, all the data object provides you some helper methods like:
417
+
-`toArray()` to obtain the data in a PHP array;
418
+
-`toJson()` to obtain a JSON string;
419
+
-`dump()` for debugging purposes, it prints on standard output the indented JSON.
0 commit comments