|
| 1 | +# Adding a New API Version to Shopify API PHP |
| 2 | + |
| 3 | +## Overview |
| 4 | +This guide provides step-by-step instructions for adding a new API version to the Shopify API PHP library. This example uses the addition of the 2025-07 API version as a reference, but the process applies to any new API version. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | +- Understanding of any breaking changes or removed resources in the new API version |
| 8 | + |
| 9 | +## Step 1: Update API Version Constants |
| 10 | + |
| 11 | +### Add New Version Constant |
| 12 | +Edit `src/ApiVersion.php` to add your new version: |
| 13 | + |
| 14 | +```php |
| 15 | +// Add the new constant following the naming pattern |
| 16 | +public const JULY_2025 = "2025-07"; // Replace with your version |
| 17 | + |
| 18 | +// If this is the latest version, update the LATEST constant |
| 19 | +public const LATEST = self::JULY_2025; // Update from previous latest |
| 20 | +``` |
| 21 | + |
| 22 | +**Naming Convention:** |
| 23 | +- Format: `{MONTH}_{YEAR}` |
| 24 | +- Examples: `APRIL_2025`, `JULY_2025`, `OCTOBER_2025` |
| 25 | + |
| 26 | +## Step 2: Create Directory Structure |
| 27 | + |
| 28 | +### Create Source Directory |
| 29 | +```bash |
| 30 | +mkdir src/Rest/Admin{YYYY_MM}/ |
| 31 | +``` |
| 32 | +Example: `src/Rest/Admin2025_07/` |
| 33 | + |
| 34 | +### Create Test Directory |
| 35 | +```bash |
| 36 | +mkdir tests/Rest/Admin{YYYY_MM}/ |
| 37 | +``` |
| 38 | +Example: `tests/Rest/Admin2025_07/` |
| 39 | + |
| 40 | +## Step 3: Copy and Update Resource Files |
| 41 | + |
| 42 | +### Copy Previous Version's Files |
| 43 | +Copy all files from the most recent API version directory: |
| 44 | + |
| 45 | +```bash |
| 46 | +# Copy source files |
| 47 | +cp -r src/Rest/Admin{PREVIOUS_VERSION}/* src/Rest/Admin{NEW_VERSION}/ |
| 48 | + |
| 49 | +# Copy test files |
| 50 | +cp -r tests/Rest/Admin{PREVIOUS_VERSION}/* tests/Rest/Admin{NEW_VERSION}/ |
| 51 | +``` |
| 52 | + |
| 53 | +### Update Each Resource File |
| 54 | +For each PHP file in the new directory, update: |
| 55 | + |
| 56 | +1. **Namespace** |
| 57 | + ```php |
| 58 | + // From |
| 59 | + namespace Shopify\Rest\Admin{PREVIOUS_VERSION}; |
| 60 | + |
| 61 | + // To |
| 62 | + namespace Shopify\Rest\Admin{NEW_VERSION}; |
| 63 | + ``` |
| 64 | + |
| 65 | +2. **API Version String** |
| 66 | + ```php |
| 67 | + // From |
| 68 | + public static string $API_VERSION = "{PREVIOUS_VERSION}"; |
| 69 | + |
| 70 | + // To |
| 71 | + public static string $API_VERSION = "{NEW_VERSION}"; |
| 72 | + ``` |
| 73 | + |
| 74 | +### Example Resource File Update |
| 75 | + |
| 76 | +**Before (Admin2025_04/Article.php)**: |
| 77 | +```php |
| 78 | +namespace Shopify\Rest\Admin2025_04; |
| 79 | + |
| 80 | +use Shopify\Auth\Session; |
| 81 | +use Shopify\Rest\Base; |
| 82 | + |
| 83 | +class Article extends Base |
| 84 | +{ |
| 85 | + public static string $API_VERSION = "2025-04"; |
| 86 | + // ... rest of the file is identical |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +**After (Admin2025_07/Article.php)**: |
| 91 | +```php |
| 92 | +namespace Shopify\Rest\Admin2025_07; |
| 93 | + |
| 94 | +use Shopify\Auth\Session; |
| 95 | +use Shopify\Rest\Base; |
| 96 | + |
| 97 | +class Article extends Base |
| 98 | +{ |
| 99 | + public static string $API_VERSION = "2025-07"; |
| 100 | + // ... rest of the file is identical |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## Step 4: Update Test Files |
| 105 | + |
| 106 | +### Rename Test Files |
| 107 | +Update the naming convention for test files: |
| 108 | +``` |
| 109 | +{ResourceName}{YYYYMM}Test.php |
| 110 | +``` |
| 111 | +Example: `Article202504Test.php` → `Article202507Test.php` |
| 112 | + |
| 113 | +### Update Test File Contents |
| 114 | +For each test file, update: |
| 115 | + |
| 116 | +1. **Use Statement** |
| 117 | + ```php |
| 118 | + // From |
| 119 | + use Shopify\Rest\Admin{PREVIOUS_VERSION}\Article; |
| 120 | + |
| 121 | + // To |
| 122 | + use Shopify\Rest\Admin{NEW_VERSION}\Article; |
| 123 | + ``` |
| 124 | + |
| 125 | +2. **Context API Version** |
| 126 | + ```php |
| 127 | + // From |
| 128 | + Context::$API_VERSION = "{PREVIOUS_VERSION}"; |
| 129 | + |
| 130 | + // To |
| 131 | + Context::$API_VERSION = "{NEW_VERSION}"; |
| 132 | + ``` |
| 133 | + |
| 134 | +3. **URL Paths in Mock Requests** |
| 135 | + ```php |
| 136 | + // From |
| 137 | + "https://test-shop.myshopify.io/admin/api/{PREVIOUS_VERSION}/..." |
| 138 | + |
| 139 | + // To |
| 140 | + "https://test-shop.myshopify.io/admin/api/{NEW_VERSION}/..." |
| 141 | + ``` |
| 142 | + |
| 143 | +## Step 5: Handle Breaking Changes |
| 144 | + |
| 145 | +### Identify Removed or Modified Resources |
| 146 | +Check the Shopify API changelog for: |
| 147 | +- Removed resources (e.g., CustomerAddress in 2025-07) |
| 148 | +- Modified endpoints |
| 149 | +- Changed field names or types |
| 150 | + |
| 151 | +### Remove Deprecated Resources |
| 152 | +If a resource is removed in the new API version: |
| 153 | +1. Delete the resource file from `src/Rest/Admin{NEW_VERSION}/` |
| 154 | +2. Delete the corresponding test file from `tests/Rest/Admin{NEW_VERSION}/` |
| 155 | + |
| 156 | +### Update Modified Resources |
| 157 | +If a resource has changed: |
| 158 | +1. Update the resource class properties |
| 159 | +2. Modify the `$PATHS` array if endpoints changed |
| 160 | +3. Update method signatures if parameters changed |
| 161 | +4. Adjust test cases accordingly |
| 162 | + |
| 163 | + |
| 164 | +## Checklist |
| 165 | + |
| 166 | +- [ ] Added new version constant to `src/ApiVersion.php` |
| 167 | +- [ ] Updated `LATEST` constant if applicable |
| 168 | +- [ ] Created `src/Rest/Admin{NEW_VERSION}/` directory |
| 169 | +- [ ] Created `tests/Rest/Admin{NEW_VERSION}/` directory |
| 170 | +- [ ] Copied all resource files from previous version |
| 171 | +- [ ] Updated namespaces in all resource files |
| 172 | +- [ ] Updated API_VERSION in all resource files |
| 173 | +- [ ] Renamed all test files with new version suffix |
| 174 | +- [ ] Updated test file imports and contexts |
| 175 | +- [ ] Updated all API URLs in test mocks |
| 176 | +- [ ] Removed deprecated resources |
| 177 | +- [ ] Updated modified resources |
| 178 | +- [ ] Run all tests successfully |
0 commit comments