Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrt1m/playstation-store-api
A simple wrapper for working with PlayStation Store API 🎮
https://github.com/mrt1m/playstation-store-api
api-client php8 playstation playstation-store
Last synced: 6 days ago
JSON representation
A simple wrapper for working with PlayStation Store API 🎮
- Host: GitHub
- URL: https://github.com/mrt1m/playstation-store-api
- Owner: mrt1m
- License: mit
- Created: 2021-06-23T13:05:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-18T13:36:30.000Z (3 months ago)
- Last Synced: 2024-11-06T22:24:28.821Z (13 days ago)
- Topics: api-client, php8, playstation, playstation-store
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 50
- Watchers: 4
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# playstation-store-api
## 1. Prerequisites
* PHP 8.1 or later
## 2. Installation
The playstation-store-api can be installed using Composer by running the following command:
```sh
composer require mrt1m/playstation-store-api
```## 3. Initialization
Create Client object using the following code:
```php
API_URL, 'timeout' => 5]));
```## 4. API Requests
### 4.1. Request product data by id
```php
use PlaystationStoreApi\Request\RequestProductById;/**
* Example for https://store.playstation.com/en-us/product/UP0001-CUSA09311_00-GAME000000000000
*/
$response = $client->get(new RequestProductById('UP0001-CUSA09311_00-GAME000000000000'));
```### 4.2. Request concept data by id
```php
use PlaystationStoreApi\Request\RequestConceptById;/**
Example for https://store.playstation.com/en-us/concept/10002694
*/
$response = $client->get(new RequestConceptById('10002694'));
```### 4.3. Request catalog data
```php
use PlaystationStoreApi\Request\RequestProductList;$request = RequestProductList::createFromCategory(CategoryEnum::PS5_GAMES);
$firstPageResponse = $client->get($request);
$nextPageResponse = $client->get($request->createNextPageRequest());
```## 5. Run examples
If you want run [examples](./examples), you need:
1) Docker and docker compose
2) Execute make command for example:
```bash
make get_add_ons_by_title_id
```
3) Get api response from [response](./response) directory## 5. About request signing
For all request you need send sha256Hash. It's request signature.
You can get sha256Hash from browser request:
1) Open the Network panel and find query to https://web.np.playstation.com/api/graphql/v1/op
2) Copy the full request URL and use urldecode
3) sha256Hash is in the extensions parameter, example:```
https://web.np.playstation.com/api/graphql/v1/op?operationName=categoryGridRetrieve&variables={"id":"44d8bb20-653e-431e-8ad0-c0a365f68d2f","pageArgs":{"size":24,"offset":0},"sortBy":{"name":"productReleaseDate","isAscending":false},"filterBy":[],"facetOptions":[]}&extensions={"persistedQuery":{"version":1,"sha256Hash":"9845afc0dbaab4965f6563fffc703f588c8e76792000e8610843b8d3ee9c4c09"}}
```
If default sha256Hash will be blocked, you can replace the base value:
1) Get new sha256Hash value
2) Replace the default value in ``PlaystationStoreApi\RequestLocatorService``
```php
use PlaystationStoreApi\RequestLocatorService;
use PlaystationStoreApi\Request\RequestPSPlusTier;$customRequestLocatorService = RequestLocatorService::default();
$customRequestLocatorService->set(RequestPSPlusTier::class, 'new sha256Hash value')
```
3) Give $customRequestLocatorService to client
```php
declare(strict_types=1);use PlaystationStoreApi\Client;
use GuzzleHttp\Client as HTTPClient;
use PlaystationStoreApi\Enum\CategoryEnum;
use PlaystationStoreApi\Enum\RegionEnum;const API_URL = 'https://web.np.playstation.com/api/graphql/v1/';
$client = new Client(
RegionEnum::UNITED_STATES,
new HTTPClient(['base_uri' => API_URL, 'timeout' => 5]),
$customRequestLocatorService
);
```## 6. Custom request
If you need custom request:
1) Create new request class then implement ``PlaystationStoreApi\Request\BaseRequest``
2) Append new request class with sha256Hash to ``PlaystationStoreApi\RequestLocatorService``
3) Give new RequestLocatorService to client
4) Execute client ``get`` method with new request## 7. Postman collection
You can try playstation api with [postman](https://www.postman.com/).
For import collection download [playstation api.postman_collection.json](./postman_collection/playstation%20api.postman_collection.json)