{"id":4880,"library":"app-store-server-library","title":"App Store Server Library","description":"The App Store Server Library is an official Python SDK provided by Apple for interacting with the App Store Server API. It simplifies backend tasks such as validating in-app purchases, retrieving transaction history, managing subscriptions, and checking the status of app purchases. Version 3.0.0 is the latest major release, aligning with the App Store Server API V2, and is actively maintained with updates typically following Apple's API evolution.","status":"active","version":"3.0.0","language":"en","source_language":"en","source_url":"https://github.com/apple/app-store-server-library-python","tags":["apple","app-store","iap","server-api","in-app-purchase","transaction-verification","subscription-management"],"install":[{"cmd":"pip install app-store-server-library","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"AppStoreServerAPIClient","correct":"from appstoreserverlibrary import AppStoreServerAPIClient"},{"symbol":"Environment","correct":"from appstoreserverlibrary import Environment"}],"quickstart":{"code":"import os\nfrom appstoreserverlibrary import AppStoreServerAPIClient, Environment\n\n# Ensure these environment variables are set for sandbox or production\nSIGNING_KEY = os.environ.get(\"APP_STORE_SIGNING_KEY\", \"\")\nKEY_ID = os.environ.get(\"APP_STORE_KEY_ID\", \"\")\nISSUER_ID = os.environ.get(\"APP_STORE_ISSUER_ID\", \"\")\nBUNDLE_ID = os.environ.get(\"APP_STORE_BUNDLE_ID\", \"\")\n\n# Use SANDBOX for testing, PRODUCTION for live apps\nENVIRONMENT = Environment.SANDBOX # or Environment.PRODUCTION\n\nif not all([SIGNING_KEY, KEY_ID, ISSUER_ID, BUNDLE_ID]):\n    print(\"Please set APP_STORE_SIGNING_KEY, APP_STORE_KEY_ID, APP_STORE_ISSUER_ID, and APP_STORE_BUNDLE_ID environment variables.\")\nelse:\n    try:\n        client = AppStoreServerAPIClient(\n            signing_key=SIGNING_KEY,\n            key_id=KEY_ID,\n            issuer_id=ISSUER_ID,\n            bundle_id=BUNDLE_ID,\n            environment=ENVIRONMENT\n        )\n        print(\"AppStoreServerAPIClient initialized successfully.\")\n\n        # Example: Get subscription status for an original transaction ID\n        # For this to run, replace 'YOUR_ORIGINAL_TRANSACTION_ID' with a real one.\n        original_transaction_id = os.environ.get(\"APP_STORE_ORIGINAL_TRANSACTION_ID\", \"\")\n        if original_transaction_id:\n            print(f\"Fetching subscription status for: {original_transaction_id}\")\n            try:\n                status_response = client.get_status_of_subscriptions(original_transaction_id)\n                print(f\"Subscription Status: {status_response.to_json()}\")\n            except Exception as e:\n                print(f\"Error fetching subscription status: {e}\")\n        else:\n            print(\"Set APP_STORE_ORIGINAL_TRANSACTION_ID env var to run subscription status example.\")\n\n    except Exception as e:\n        print(f\"Error initializing AppStoreServerAPIClient or making API call: {e}\")","lang":"python","description":"Initializes the AppStoreServerAPIClient with credentials from environment variables and demonstrates fetching subscription status using a placeholder original transaction ID. Remember to configure your App Store Connect API Key, Issuer ID, and Bundle ID."},"warnings":[{"fix":"Migrate code to use `client.get_transaction_info(transaction_id)` or other relevant V2 endpoints provided by the library.","message":"Apple's App Store Server API deprecated the `verify_receipt` endpoint. The App Store Server Library reflects this, and its `AppStoreServerAPIClient` no longer provides a `verify_receipt` method. For individual transactions, use `get_transaction_info` or `get_all_transaction_info`. For broader purchase data, use `get_transaction_history` or `get_status_of_subscriptions`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update client initialization to use `signing_key` and verify parameter order according to the documentation for versions 2.0.0 and above.","message":"The `AppStoreServerAPIClient` constructor changed significantly in version 2.0.0 (and is retained in 3.0.0). The `private_key` parameter was renamed to `signing_key`, and the parameter order changed. Ensure you are providing the correct arguments: `(signing_key, key_id, issuer_id, bundle_id, environment)`.","severity":"breaking","affected_versions":"<2.0.0 (when migrating to >=2.0.0)"},{"fix":"Dynamically select the environment based on your application's deployment context or the source of the transaction ID (e.g., check `is_upgraded_from_android_in_app_billing` or other cues).","message":"Always ensure the `Environment` passed to the `AppStoreServerAPIClient` (e.g., `Environment.SANDBOX` or `Environment.PRODUCTION`) matches the environment where your transactions occurred. Using `SANDBOX` for a production `transaction_id` or vice-versa will result in verification failures (e.g., HTTP 404 Not Found if transaction ID is not found in the specified environment).","severity":"gotcha","affected_versions":"*"},{"fix":"Double-check all four credential values against your App Store Connect account (Users and Access -> Keys; ensure the key is active). Load the private key content correctly, for example, by reading the `.p8` file into a string.","message":"Incorrectly configured `signing_key`, `key_id`, `issuer_id`, or `bundle_id` will lead to authentication errors (e.g., HTTP 401 Unauthorized or 403 Forbidden). The `signing_key` must be the *content* of the private key (`.p8` file), not a file path. Ensure your bundle ID matches the app associated with the credentials.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}