How to update in-app purchase prices using the app store connect API

Documentation for the App Store Connect API is poor, especially in comparison to the good documentation for the now-defunct XML-based "transporter" API. In the hope that it will be useful to others trying to do this in the future, here is how I was able to do a bulk update of my in-app purchases' prices using the API.

Step 1: get the IDs for the IAPs, if you don't already know them:

GET v1/apps/$app/inAppPurchasesV2

If you have a lot of IAPs, follow any links/next URL to get subsequent pages.

The ids are in data/id .

Step 2: get the current prices, if you don't already know them.

I believe you need to do a separate request for each IAP (right?).

GET v1/inAppPurchasePriceSchedules/$iap/manualPrices?include=inAppPurchasePricePoint,territory

The price and currency are in included/attributes/customerPrice and included/attributes/currency (I generally only have one "manual" price).

Step 3: look up the available price points:

GET v2/inAppPurchases/$iap/pricePoints?filter[territory]=$territory

The prices and IDs are in data/attributes/customerPrice and data/id.

Note this query takes the specific IAP ID. I don't know why. Are the price points specific to the IAPs? Can I reuse a price point ID that I've looked up for one IAP with another IAP for the same app?

Step 4: choose your new prices.

Step 5: Submit the new prices:

POST v1/inAppPurchasePriceSchedules

  {
    "data" : {
      "relationships" : {
        "baseTerritory" : {
          "data" : {
            "id" : "$territory",
            "type" : "territories"
          }
        },
        "inAppPurchase" : {
          "data" : {
            "id" : "$iap",
            "type" : "inAppPurchases"
          }
        },
        "manualPrices" : {
          "data" : [
            {
              "id" : "$random_id",
              "type" : "inAppPurchasePrices"
            }
          ]
        }
      },
      "type" : "inAppPurchasePriceSchedules"
    },
    "included" : [
      {
        "attributes" : {
          "startDate" : null,
          "endDate" : null
        },
        "id" : "$random_id",
        "relationships" : {
          "inAppPurchasePricePoint" : {
            "data" : {
              "id" : "$price_point_id",
              "type" : "inAppPurchasePricePoints"
            }
          },
          "inAppPurchaseV2" : {
            "data" : {
              "id" : "$iap",
              "type" : "inAppPurchases"
            }
          }
        },
        "type" : "inAppPurchasePrices"
      }
    ]
  }

In that, $iap is the IAP ID from step 1, $territory is probably a three-letter string like GBR, $random_id is a random identifier that you generate (using the same value in the two places) (I'm not sure what the scope of this is; do I have to check that I don't accidentally send the same value in the future, or does it only exist while this submission is processed?), and $price_point_id is the ID for the price point from step 3.

I believe it is necessary to send a separate submission for each IAP (right?)

That example makes the change immediately (start and end dates are both null). Note that if you want to schedule a future change, you need to include both the current period and price and the future period and price in the submission.

I would like to thank @Efun whose posts in this thread: https://developer.apple.com/forums/thread/727159 helped a lot with understanding this.

How to update in-app purchase prices using the app store connect API
 
 
Q