PHPackages                             shopify/shopify-app-php - 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. shopify/shopify-app-php

ActiveLibrary

shopify/shopify-app-php
=======================

Package for building Shopify apps. Authored and maintained by Shopify.

v0.1.4(2mo ago)401.8k↓25%1MITPHPPHP &gt;=8.2CI passing

Since Jan 9Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/Shopify/shopify-app-php)[ Packagist](https://packagist.org/packages/shopify/shopify-app-php)[ Docs](https://packagist.org/packages/shopify/shopify-app-php)[ RSS](/packages/shopify-shopify-app-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (10)Used By (1)

Shopify App PHP Package
=======================

[](#shopify-app-php-package)

PHP package for building Shopify applications.

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

[](#installation)

```
composer require shopify/shopify-app-php
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- firebase/php-jwt for JWT token handling
- guzzlehttp/guzzle for HTTP requests

Features
--------

[](#features)

Request Verification:

- `verifyAdminUIExtReq`: Requests from Admin UI extensions
- `verifyAppHomeReq`: Requests for embedded app home that use App Bridge
- `verifyAppProxyReq`: Requests from storefronts via App Proxy
- `verifyCheckoutUIExtReq`: Requests from checkout UI extensions
- `verifyCustomerAccountUIExtReq`: Requests from Customer account UI extensions
- `verifyFlowActionReq`: Requests from Flow action extensions
- `verifyPosUIExtReq`: Requests from POS UI extensions
- `verifyWebhookReq`: Webhook requests

Exchange:

- `exchangeUsingTokenExchange`: Use Token Exchange to exchange an ID token for an access token
- `exchangeUsingClientCredentials`: Get access tokens via client credentials
- `refreshTokenExchangedAccessToken`: Refresh an access token that was created using Token Exchange

GraphQL:

- `adminGraphQLRequest`: Make Admin API GraphQL requests with automatic retry handling

Helpers:

- `appHomePatchIdToken`: Render the patch ID token page for embedded apps
- `appHomeParentRedirect`: Asks the parent (Shopify admin) to redirect to a new URL, breaking out of the iframe
- `appHomeRedirect`: Redirects to a relative URL within the app home iframe

Principles
----------

[](#principles)

1. **Built-in best practices:** This package encodes best practices for building Shopify apps as primitives. Use them correctly and you'll build secure, performant apps on the green-path.
2. **What most apps need most of the time:** This package does not intend to focus on some less common features of the Shopify app platform (e.g: Non Embedded apps).
3. **Framework agnostic:** Whether you're using Laravel, Symfony, CodeIgniter, or raw PHP, these packages won't force architectural decisions on you. We provide primitives. You compose them however you wish. We've prototyped extensively to make sure that composition can lead to idiomatic patterns.
4. **Language agnostic:** Whilst this is a PHP package, its API is shared with a Python package. This creates some interesting constraints, and sacrifices some idioms. But... the big benefit is that fixes in one community will benefit the other. As the Python package evolves, so will the PHP package (and vice-versa).

Setup steps
-----------

[](#setup-steps)

This section will focus on steps that are universal to any web framework. We'll provide examples for Laravel, Symfony and CodeIgniter. But these examples are fairly universal and can be translated to other approaches.

### Install the Shopify CLI

[](#install-the-shopify-cli)

This installs Shopify CLI globally on your system, so you can run shopify commands from any directory.

```
npm install -g @shopify/cli@latest

```

Please see [this guide](https://shopify.dev/docs/api/shopify-cli#installation) for using other JavaScript package managers

### Initialize your web framework

[](#initialize-your-web-framework)

- [Laravel quickstart](https://laravel.com/docs/installation)
- [Symfony quickstart](https://symfony.com/doc/current/setup.html)
- [CodeIgniter quickstart](https://codeigniter.com/user_guide/installation/index.html)

### Setup the Shopify CLI

[](#setup-the-shopify-cli)

Inside the directory where you initialized your framework create a `shopify.app.toml` (This will be overwritten when you run `shopify app init --reset`):

```
client_id = ""
name = ""
application_url = ""
embedded = true

[access_scopes]
scopes = "write_products"

[webhooks]
api_version = "2025-01"
```

Make sure there is at-least a minimal `package.json`:

```
{
  "name": "my-php-app"
}
```

Create a `shopify.web.toml`:

```
name = "My PHP App"
roles = ["frontend", "backend"]
webhooks_path = "/webhooks/app/uninstalled"

[commands]
dev = "[COMMAND]"
```

Replace `[COMMAND]` with the command to run your app in development mode. For example:

- Laravel: `php artisan serve`
- Symfony: `symfony server:start --port=${PORT:-8000} --allow-http`
- CodeIgniter: `php spark serve --port=${PORT:-8080}`

Note: The Shopify CLI provides `PORT` and `SERVER_PORT` environment variables. Laravel automatically uses the `SERVER_PORT` environment variable.

### Run your app

[](#run-your-app)

With these setup steps complete you should be able to run

```
shopify app dev --reset
```

Only use the `--reset` flag the first time.

Using the package
-----------------

[](#using-the-package)

### Initialization

[](#initialization)

`SHOPIFY_API_KEY` and `SHOPIFY_API_SECRET` are provided by the Shopify CLI.

```
