|
| 1 | +--- |
| 2 | +description: >- |
| 3 | + A comprehensive guide to help you transition from V1 to V2 of the Request |
| 4 | + Network API |
| 5 | +--- |
| 6 | + |
| 7 | +# Migrate to V2 |
| 8 | + |
| 9 | +{% hint style="warning" %} |
| 10 | +**V1 API Deprecation Notice** |
| 11 | + |
| 12 | +V1 of the Request Network API is deprecated and in security-fixes-only mode. This means: |
| 13 | + |
| 14 | +* **Deprecated**: We strongly recommend upgrading to V2 |
| 15 | +* **Security-fixes-only**: V1 will only receive critical security patches, no new features, enhancements, or non-security bug fixes |
| 16 | + |
| 17 | +Please migrate to V2 as soon as possible to ensure continued support and access to the latest features. |
| 18 | +{% endhint %} |
| 19 | + |
| 20 | +The Request Network API V2 introduces significant improvements while maintaining backward compatibility. This guide provides a comprehensive overview of the breaking changes between V1 and V2, along with a step-by-step migration guide. |
| 21 | + |
| 22 | +{% hint style="info" %} |
| 23 | +**Important**: V2 is designed to coexist with V1. You can migrate incrementally and don't need to migrate all endpoints at once. |
| 24 | +{% endhint %} |
| 25 | + |
| 26 | +## Breaking Changes from V1 to V2 |
| 27 | + |
| 28 | +### Core Architectural Changes |
| 29 | + |
| 30 | +**Path Parameter Changes** |
| 31 | + |
| 32 | +* **V1**: Uses `paymentReference` as the path parameter |
| 33 | +* **V2**: Uses `requestId` as the path parameter |
| 34 | + |
| 35 | +**Response Schema Standardization** |
| 36 | + |
| 37 | +* **V1**: Returns `requestID` (uppercase D) in create responses |
| 38 | +* **V2**: Returns `requestId` (lowercase d) in create responses |
| 39 | + |
| 40 | +**Enhanced Validation** |
| 41 | + |
| 42 | +* **V2**: Stricter type checking and validation schemas |
| 43 | +* **V1**: More permissive validation |
| 44 | + |
| 45 | +## API Interface Differences |
| 46 | + |
| 47 | +### Endpoint Structure Changes |
| 48 | + |
| 49 | +#### Request Endpoints |
| 50 | + |
| 51 | +| Feature | V1 Endpoint | V2 Endpoint | |
| 52 | +| ------------------ | ------------------------------------------- | ------------------------------------ | |
| 53 | +| Create Request | `POST /v1/request` | `POST /v2/request` | |
| 54 | +| Get Request | `GET /v1/request/{paymentReference}` | `GET /v2/request/{requestId}` | |
| 55 | +| Get Request Status | `GET /v1/request/{paymentReference}/status` | `GET /v2/request/{requestId}/status` | |
| 56 | + |
| 57 | +#### Payment Endpoints |
| 58 | + |
| 59 | +| Feature | V1 Endpoint | V2 Endpoint | |
| 60 | +| -------------------- | ------------------------------------------- | ------------------------------------ | |
| 61 | +| Get Payment Calldata | `GET /v1/request/{paymentReference}/pay` | `GET /v2/request/{requestId}/pay` | |
| 62 | +| Get Payment Routes | `GET /v1/request/{paymentReference}/routes` | `GET /v2/request/{requestId}/routes` | |
| 63 | + |
| 64 | +### Request Schema Differences |
| 65 | + |
| 66 | +#### Create Request Schema |
| 67 | + |
| 68 | +**V1 Schema:** |
| 69 | + |
| 70 | +```json |
| 71 | +{ |
| 72 | + "amount": "string", |
| 73 | + "payee": "string", |
| 74 | + "invoiceCurrency": "string", |
| 75 | + "paymentCurrency": "string" |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +**V2 Schema:** |
| 80 | + |
| 81 | +```json |
| 82 | +{ |
| 83 | + "amount": "string", |
| 84 | + "payee": "string", |
| 85 | + "invoiceCurrency": "string", |
| 86 | + "paymentCurrency": "string" |
| 87 | + // V2 accepts additional optional fields for extended functionality |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +#### Create Response Schema |
| 92 | + |
| 93 | +**V1 Response:** |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "requestID": "string", // Note: uppercase D |
| 98 | + "paymentReference": "string" |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +**V2 Response:** |
| 103 | + |
| 104 | +```json |
| 105 | +{ |
| 106 | + "requestId": "string", // Note: lowercase d |
| 107 | + "paymentReference": "string" |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### Payment Query Parameter Differences |
| 112 | + |
| 113 | +#### Pay Request Query Parameters |
| 114 | + |
| 115 | +**V1 Query Parameters:** |
| 116 | + |
| 117 | +```typescript |
| 118 | +interface PayRequestQueryV1 { |
| 119 | + payerAddress?: string; |
| 120 | + routeId?: string; |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +**V2 Query Parameters:** |
| 125 | + |
| 126 | +```typescript |
| 127 | +interface PayRequestQueryV2 { |
| 128 | + payerAddress?: string; |
| 129 | + routeId?: string; |
| 130 | + // Enhanced validation with stricter type checking |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +## Step-by-Step Migration Guide |
| 135 | + |
| 136 | +### Phase 1: Assessment and Planning |
| 137 | + |
| 138 | +1. **Audit Your Current Integration** |
| 139 | + * List all V1 endpoints you're currently using |
| 140 | + * Identify which features you need (basic payments vs advanced features) |
| 141 | +2. **Choose Migration Strategy** |
| 142 | + * **Incremental**: Migrate endpoints one by one (recommended) |
| 143 | + * **Full Migration**: Switch all endpoints at once |
| 144 | + * **Parallel**: Run V1 and V2 side by side |
| 145 | + |
| 146 | +### Phase 2: Update Path Parameters |
| 147 | + |
| 148 | +#### Before (V1): |
| 149 | + |
| 150 | +```typescript |
| 151 | +// Get request status |
| 152 | +const response = await fetch(`/v1/request/${paymentReference}/status`); |
| 153 | + |
| 154 | +// Get payment calldata |
| 155 | +const payData = await fetch(`/v1/request/${paymentReference}/pay?payerAddress=${address}`); |
| 156 | +``` |
| 157 | + |
| 158 | +#### After (V2): |
| 159 | + |
| 160 | +```typescript |
| 161 | +// Get request status |
| 162 | +const response = await fetch(`/v2/request/${requestId}/status`); |
| 163 | + |
| 164 | +// Get payment calldata |
| 165 | +const payData = await fetch(`/v2/request/${requestId}/pay?payerAddress=${address}`); |
| 166 | +``` |
| 167 | + |
| 168 | +### Phase 3: Update Response Handling |
| 169 | + |
| 170 | +#### Before (V1): |
| 171 | + |
| 172 | +```typescript |
| 173 | +const createResponse = await fetch('/v1/request', { |
| 174 | + method: 'POST', |
| 175 | + body: JSON.stringify(requestData) |
| 176 | +}); |
| 177 | + |
| 178 | +const { requestID, paymentReference } = await createResponse.json(); |
| 179 | +// Note: requestID with uppercase D |
| 180 | +``` |
| 181 | + |
| 182 | +#### After (V2): |
| 183 | + |
| 184 | +```typescript |
| 185 | +const createResponse = await fetch('/v2/request', { |
| 186 | + method: 'POST', |
| 187 | + body: JSON.stringify(requestData) |
| 188 | +}); |
| 189 | + |
| 190 | +const { requestId, paymentReference } = await createResponse.json(); |
| 191 | +// Note: requestId with lowercase d |
| 192 | +``` |
| 193 | + |
| 194 | +### Phase 4: Update Error Handling |
| 195 | + |
| 196 | +V2 has enhanced error responses with more specific error codes: |
| 197 | + |
| 198 | +```typescript |
| 199 | +try { |
| 200 | + const response = await fetch('/v2/request', { |
| 201 | + method: 'POST', |
| 202 | + body: JSON.stringify(requestData) |
| 203 | + }); |
| 204 | + |
| 205 | + if (!response.ok) { |
| 206 | + const error = await response.json(); |
| 207 | + |
| 208 | + // V2 provides more detailed error information |
| 209 | + console.error('Error:', error.message); |
| 210 | + console.error('Status Code:', error.statusCode); |
| 211 | + console.error('Error Code:', error.error); |
| 212 | + } |
| 213 | +} catch (error) { |
| 214 | + console.error('Request failed:', error); |
| 215 | +} |
| 216 | +``` |
| 217 | + |
| 218 | +### Phase 5: Testing and Validation |
| 219 | + |
| 220 | +1. **Test Core Functionality** |
| 221 | + * Create requests using V2 endpoints |
| 222 | + * Verify payment flows work correctly |
| 223 | + * Check response formats match expectations |
| 224 | +2. **Enhanced Validation Testing** |
| 225 | + * Test stricter type checking |
| 226 | + * Verify improved error responses |
| 227 | +3. **Performance Testing** |
| 228 | + * Compare response times between V1 and V2 |
| 229 | + * Test with realistic data volumes |
| 230 | + |
| 231 | +## Support and Resources |
| 232 | + |
| 233 | +* **Migration Support**: [Book a call](https://calendly.com/mariana-rn/request-network-demo-docs) with our team for migration assistance |
| 234 | +* **GitHub Examples**: Check the `easy-invoice` repository for V2 implementation examples |
| 235 | + |
| 236 | +## Backward Compatibility |
| 237 | + |
| 238 | +V1 endpoints will continue to work during the migration period. However, we recommend migrating to V2 to access improvements and future features: |
| 239 | + |
| 240 | +* Enhanced security and validation |
| 241 | +* Better error handling and debugging |
| 242 | +* Improved webhook events |
| 243 | +* Access to new features as they are released |
| 244 | + |
| 245 | +V2 is the foundation for all future Request Network API features and improvements. |
| 246 | + |
0 commit comments