app-store-server-api
A Node.js client for the App Store Server API.
Features
- History, subscription status and order lookup endpoints
- Typed responses (i.e. you get auto-complete for the fields in the response)
- Manages authentication tokens for you
- Helpers to decode JWS items
- Performs certificate validation against Apple's CA.
- Types and helpers for App Store Server Notifications V2
Requirements
Node.js 15.6.0 or newer
Installation
npm install app-store-server-api
Usage
Prerequisites
To get started, you must obtain the following:
A note on the issuer ID:
Apple's documentation currently has incorrect instructions on how to obtain this.
To get your issuer ID, you must create an API key for App Store Connect (not the App Store Server API). Only after creating your first API key will the issuer ID appear.
Create a client
const { AppStoreServerAPI, Environment } = require("app-store-server-api")
import { AppStoreServerAPI, Environment } from "app-store-server-api"
const KEY =
`-----BEGIN PRIVATE KEY-----
MHcCAQEEIPWH5lyoG7Wbzv71ntF6jNvFwwJLKYmPWN/KBD4qJfMcoAoGCCqGSM49
AwEHoUQDQgAEMOlUa/hmyAPU/RUBds6xzDO8QNrTFhFwzm8E4wxDnSAx8R9WOMnD
cVGdtnbLFIdLk8g4S7oAfV/gGILKuc+Vqw==
-----END PRIVATE KEY-----`
const KEY_ID = "ABCD123456"
const ISSUER_ID = "91fa5999-7b54-4363-a2a8-265363fa6cbe"
const APP_BUNDLE_ID = "com.yourcompany.app"
const api = new AppStoreServerAPI(
KEY, KEY_ID, ISSUER_ID, APP_BUNDLE_ID, Environment.Production
)
History
const response = await api.getTransactionHistory(originalTransactionId)
const transactions = await api.decodeTransactions(response.signedTransactions)
for (let transaction of transactions) {
}
if (response.hasMore) {
const nextResponse = await api.getTransactionHistory(originalTransactionId, response.revision)
}
Subscription status
const response = await api.getSubscriptionStatuses(originalTransactionId)
const item = response.data[0].lastTransactions.find(item => item.originalTransactionId === originalTransactionId)
const transactionInfo = await api.decodeTransaction(item.signedTransactionInfo)
const renewalInfo = await api.decodeRenewalInfo(item.signedRenewalInfo)
Order lookup
import { OrderLookupStatus } from "app-store-server-api"
const response = await api.lookupOrder(orderId)
if (response.orderLookupStatus === OrderLookupStatus.Valid) {
const transactions = await api.decodeTransactions(response.signedTransactions)
}
Server notifications
While not exactly part of the App Store Server API, App Store Server Notifications (version 2) is closely related and uses some of the same types and encoding format as the API. For that reason this package includes a function to help you decode notifications (which will also verify their signature).
import { decodeNotificationPayload } from "app-store-server-api"
const payload = await decodeNotificationPayload(signedPayload)
if (payload.data.bundleId === APP_BUNDLE_ID) {
}
Resources
WWDC videos:
License
MIT