PHPackages                             mantix/app-store-connect-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mantix/app-store-connect-api

ActiveLibrary[API Development](/categories/api)

mantix/app-store-connect-api
============================

A PHP client library for accessing App Store Connect APIs

v1.1(1y ago)01581MITPHPPHP ^7.4|^8.0

Since Mar 23Pushed 1y agoCompare

[ Source](https://github.com/Mantix/app-store-connect-api-php)[ Packagist](https://packagist.org/packages/mantix/app-store-connect-api)[ RSS](/packages/mantix-app-store-connect-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

App Store Connect APIs Client Library for PHP
=============================================

[](#app-store-connect-apis-client-library-for-php)

[![GitHub Release](https://camo.githubusercontent.com/3c69734b7e99a09d7e3c066b4e1e53ac288d60d2be3db269ea825351cebe988e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d616e7469782f6170702d73746f72652d636f6e6e6563742d617069)](https://camo.githubusercontent.com/3c69734b7e99a09d7e3c066b4e1e53ac288d60d2be3db269ea825351cebe988e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d616e7469782f6170702d73746f72652d636f6e6e6563742d617069)[![Packagist Downloads](https://camo.githubusercontent.com/08ed061cfbfb3815251a9da1747f28e437de1136272632b10090427cf6661121/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616e7469782f6170702d73746f72652d636f6e6e6563742d617069)](https://camo.githubusercontent.com/08ed061cfbfb3815251a9da1747f28e437de1136272632b10090427cf6661121/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616e7469782f6170702d73746f72652d636f6e6e6563742d617069)[![Packagist License](https://camo.githubusercontent.com/c31e3799dca5824e0c29dbc6acc79c6a5bb4fda93d8f2dae3ab3e2e19355d73d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d616e7469782f6170702d73746f72652d636f6e6e6563742d617069)](https://camo.githubusercontent.com/c31e3799dca5824e0c29dbc6acc79c6a5bb4fda93d8f2dae3ab3e2e19355d73d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d616e7469782f6170702d73746f72652d636f6e6e6563742d617069)[![Packagist Dependency Version](https://camo.githubusercontent.com/bebbc3806f13fe823c3a368494077ba0be4221929859b6f852661718bd6279d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6d616e7469782f6170702d73746f72652d636f6e6e6563742d6170692f706870)](https://camo.githubusercontent.com/bebbc3806f13fe823c3a368494077ba0be4221929859b6f852661718bd6279d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6d616e7469782f6170702d73746f72652d636f6e6e6563742d6170692f706870)

Overview
--------

[](#overview)

This library enables developers to automate their interactions with App Store Connect. It's a fork of the excellent [cantie/app-store-connect-api-php](https://github.com/cantie/app-store-connect-api-php) package, updated to work with modern PHP frameworks including Laravel 10+ and Carbon 3.x.

The client was originally modified from [Google API PHP Client](https://github.com/googleapis/google-api-php-client) with resources specifically added for App Store Connect APIs.

Why This Fork?
--------------

[](#why-this-fork)

This fork was created to address the following needs:

- Support for modern Laravel applications (10+)
- Compatibility with Carbon 3.x
- Future Laravel package development
- Ongoing maintenance and updates
- Enhanced documentation

We maintain high compatibility with the original package while ensuring it works in modern PHP environments.

Installation
------------

[](#installation)

The preferred method is via [composer](https://getcomposer.org/). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

```
composer require mantix/app-store-connect-api
```

Coming Soon: Laravel Package
----------------------------

[](#coming-soon-laravel-package)

We're working on a dedicated Laravel package that will provide:

- Simple configuration through Laravel's configuration system
- Integration with Laravel's service container
- Artisan commands for common App Store Connect operations
- Middleware for API rate limiting and token management
- Simple facade access to the API client

Stay tuned for `mantix/laravel-app-store-connect`.

Usage Examples
--------------

[](#usage-examples)

### Basic Example

[](#basic-example)

```
use AppleClient;
use AppleService_AppStore;
use Mantix\AppStoreConnect\Services\AppStore\CustomerReviewResponseV1CreateRequest;

$client = new AppleClient();
$client->setApiKey("PATH_TO_API_KEY");
$client->setIssuerId($issuerId);
$client->setKeyIdentifier($keyIdentifier);

$appstore = new AppleService_AppStore($client);
// Get apps by Bundle ID
$results = $appstore->apps->listApps([
    "filter[bundleId]" => "YOUR_BUNDLE_ID" // filter LIKE
]);

// Get all customer reviews for each app
foreach ($results->getData() as $app) {
    $appCustomerReviews = $appstore->apps->listAppsCustomerReviews($app->getId());
    foreach ($appCustomerReviews as $appCustomerReview) {
        // Print all reviewer's nickname
        echo $appCustomerReview->getAttributes()->getReviewerNickName(), " \n";

        // Get response for this review
        $customerReviewResponseV1Response = $appstore->customerReviews->getCustomerReviewsResponse($appCustomerReview->getId());

        // Create or update response for this review
        $postBody = new CustomerReviewResponseV1CreateRequest([
            'data' => [
                'attributes' => [
                    'responseBody' => "YOUR_REPLY_TEXT_HERE"
                ],
                'relationships' => [
                    'review' => [
                        'data' => [
                            'id' => $appCustomerReview->getId()
                        ]
                    ]
                ]
            ]
        ]);
        $customerReviewResponseV1Response = $appstore->customerReviewResponses->createCustomerReviewResponses($postBody);

        // Or just delete the response if existed
        $appstore->customerReviewResponses->deleteCustomerReviewResponses($customerReviewResponseV1Response->getData()->getId());
    }
}
```

### Create New Client

[](#create-new-client)

```
use AppleClient;

$client = new AppleClient();
$client->setApiKey("PATH_TO_API_KEY");
$client->setIssuerId($issuerId);
$client->setKeyIdentifier($keyIdentifier);
// Optional: create new JWT token. If skip this step, token are auto generated when first request are sent
$client->generateToken();
```

### Making a Request

[](#making-a-request)

For almost all requests except upload service, we use AppStore service:

```
use AppleService_AppStore;
// All resources and their methods parameters are listed in src/Service/AppStore.php
$appstore = new AppleService_AppStore($client);
// Make request, for example we call request for an Apps's resources
$appstore->apps->listAppsAppStoreVersions($APP_ID_HERE, $OPTIONAL_PARAMS);
```

For details, you can view the source code in `src/Services/AppStore/Resource/*`

### Aliases

[](#aliases)

Basic classes are aliased for convenient use, see more at `src/aliases.php`

```
$classMap = [
    'Mantix\\AppStoreConnect\\Client' => 'AppleClient',
    'Mantix\\AppStoreConnect\\Service' => 'AppleService',
    'Mantix\\AppStoreConnect\\Services\\AppStore' => 'AppleService_AppStore',
    'Mantix\\AppStoreConnect\\Services\\Upload' => 'AppleService_Upload'
];
```

### Upload Assets to App Store Connect

[](#upload-assets-to-app-store-connect)

In this example we will upload one screenshot file to app screenshot set:

```
// Firstly, we get app screenshot set step by step, we can reduce steps by include[] parameters in query
use AppleService_Upload;
use Mantix\AppStoreConnect\Services\AppStore\AppScreenshotCreateRequest;
use Mantix\AppStoreConnect\Services\AppStore\AppScreenshotUpdateRequest;

$appId = $app->getId(); // $app from previous example
$appStoreVersions = $appstore->apps->listAppsAppStoreVersions($appId);
// Get first app store version id;
$appStoreVersionId = $appStoreVersions->getData()[0]->getId();
// Get list localizations of this version
$appStoreVersionLocalizations = $appstore->appStoreVersions->listAppStoreVersionsAppStoreVersionLocalizations($appStoreVersionId);
// Get first localization id
$appStoreVersionLocalizationId = $appStoreVersionLocalizations->getData()[0]->getId();
// Get list app screenshot sets for this localization
$appScreenshotSets = $appstore->appStoreVersionLocalizations->listAppStoreVersionLocalizationsAppScreenshotSets($appStoreVersionLocalizationId);
// Get first set id
$appScreenshotSetId = $appScreenshotSets->getData()[0]->getId();

// Now, we make an asset reservation
$fileName = "YOUR_FILE_NAME";
$filePath = "FULL_PATH_TO_YOUR_FILE" . $fileName;
$requestCreateAppScreenshot = new AppScreenshotCreateRequest([
    'data' => [
        'type' => 'appScreenshots',
        'attributes' => [
            'fileSize' => filesize($filePath),
            'fileName' => $fileName
        ],
        'relationships' => [
            'appScreenshotSet' => [
                'data' => [
                    'type' => 'appScreenshotSets',
                    'id' => $appScreenshotSetId
                ]
            ]
        ]
    ]
]);
// Create new app screenshot
$appScreenshot = $appstore->appScreenshots->createAppScreenshots($requestCreateAppScreenshot);
$appScreenshotId = $appScreenshot->getData()->getId();
// Follow instruction from UploadOperation[] return in $appScreenshot to upload part or whole asset file
// We can upload parts of your asset concurrently
foreach ($appScreenshot->getData()->getAttributes()->getUploadOperations() as $uploadOperation) {
    $upload = new AppleService_Upload($client, $uploadOperation); // $client from above example
    $ret = $upload->uploadAssets->upload($uploadOperation, $filePath);
}
// Finally, commit the reservation
$appScreenshotUpdateRequest = new AppScreenshotUpdateRequest([
    'data' => [
        'type' => 'appScreenshots',
        'id' => $appScreenshotId,
        'attributes' => [
            'sourceFileChecksum' => md5_file($filePath),
            'uploaded' => true
        ]
    ]
]);
$ret = $appstore->appScreenshots->updateAppScreenshots($appScreenshotId, $appScreenshotUpdateRequest);
```

### Initialize Classes

[](#initialize-classes)

All object classes that extend from `Model.php` can be initialized with an array of attribute names and values, as in the previous example:

```
use Mantix\AppStoreConnect\Services\AppStore\AppScreenshotUpdateRequest;
$appScreenshotUpdateRequest = new AppScreenshotUpdateRequest([
    'data' => [
        'type' => 'appScreenshots',
        'id' => $appScreenshotId,
        'attributes' => [
            'sourceFileChecksum' => md5_file($filePath),
            'uploaded' => true
        ]
    ]
]);
```

### Caching

[](#caching)

JWT tokens are cached for 10 minutes and only generated if they don't exist or have expired. JWT tokens are not shared between clients. Each client has its own token as defined in `src/Client.php`:

```
public function generateToken()
{
    $tokenGenerator = new Generate($this->getApiKey(), $this->getKeyIdentifier(), $this->getIssuerId());
    $jwtToken = $tokenGenerator->generateToken();
    // cache for 10 minutes
    $this->jwtToken = $jwtToken;
    $this->jwtTokenExpTime = (new DateTime())->modify("+10 minutes")->getTimestamp();
    return $jwtToken;
}
```

Laravel Integration
-------------------

[](#laravel-integration)

While we're working on our dedicated Laravel package, here's a simple approach to integrate this library into your Laravel applications:

### Service Provider

[](#service-provider)

Create a service provider for App Store Connect API:

```
