作者:iHTCboy
一、前语
咱们在上一篇文章 《App Store 新定价机制》解说了苹果新定价晋级,本文接着来解说一下新 App Store Connect API v2.3 的运用示例。
二、App Store Connect API v2.3
关于 App Store Connect API 的根本运用和密钥创建,能够直接参阅咱们之前的文章 《运用 App Store Connect API 批量创建内购产品》,这儿就不重复展开了。咱们直接来给出恳求的示例和阐明啊。
关于 App Store Connect API version 2.3 release notes,一切恳求示例代码和呼应内容,现已上传到 GitHub 库房:
- 37iOS/AppStoreConnectAPI-Demo
App Store Connect API v2.3 更新的内容:
- 获取 App 和 运用内购买 IAP 的一切价格点(最多 900 个价格点)。
- 获取 App 价格点对应的全球均衡价格。
- 获取和办理 App 和 运用内购买 IAP 的价格表,支撑主动价格、手动价格和基准国家的装备。
- 获取和办理 App 和 运用内购买 IAP (包括订阅)的答应出售规模。
2.1 获取一切有效的国家或区域(List Territories)
由于以下的许多接口,都依赖这个接口获取到的国家或区域标识,所以先解说。这个接口是 v1.2 就有的基础接口,作用是获取 App Store 现在答应出售的一切国家和区域。
GET 恳求:
GET https://api.appstoreconnect.apple.com/v1/territories?limit=200
回来的内容,其间的我国大陆是这样:
{
"type": "territories",
"id": "CHN",
"attributes": {
"currency": "CNY"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/CHN"
}
}
现在苹果支撑 175 个国家和区域,所以在恳求链接添加 ?limit=200
,就能够不用分页,直接回来悉数的内容。别的,假如是自定 App,答应的出售国家区域与 App Store 不相同,获取接口是 List All Territories for an End User License Agreement,需求了解的能够自行查询。
2.2 获取 App 的价格点(List all price points for an app)
GET https://api.appstoreconnect.apple.com/v1/apps/{id}/appPricePoints?filter[territory]=CHN&include=territory&limit=200
回来的内容:
{
"data": [
{
"type": "appPricePoints",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ",
"attributes": {
"customerPrice": "1.0",
"proceeds": "0.84"
},
"relationships": {
"territory": {
"data": {
"type": "territories",
"id": "CHN"
}
}
}
}
],
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/apps/1240856775/appPricePoints?include=territory&filter%5Bterritory%5D=CHN&limit=200",
"next": "https://api.appstoreconnect.apple.com/v1/apps/1240856775/appPricePoints?cursor=AMg.AM99C8s&include=territory&filter%5Bterritory%5D=CHN&limit=200"
},
"meta": {
"paging": {
"total": 801,
"limit": 200
}
}
}
苹果说这个接口会回来 900 个价格点,现在只回来 801 个,其间包括一个 0.0
免费价格点。
"attributes": {
"customerPrice": "0.0",
"proceeds": "0.0"
},
别的,还有 100 个高价格点,估量是向苹果申请通往后,接口才会回来。
假如不加 ?limit=200
最大额分页的话,一切的国家和区域的价格点,有 140175 个:
"meta" : {
"paging" : {
"total" : 140175,
"limit" : 50
}
}
加上 ?limit=200
有 700 分页,所以你需求恳求 700 次!在运用时主张仍是按国家和区域码别离一个一个获取,如 filter[territory]=CHN
只获取我国大陆的价格点,由于减少恳求分页量比较便利办理。那么假如恳求超越 200 个时,应该怎么分页恳求呢?
经过 next
字段来恳求下一页,里边有一个 cursor
字段,表明下一页的游标,是不是有点傻?按道理说,用 offset=2
会不会更好一点?
"links" : {
"self" : "https://api.appstoreconnect.apple.com/v1/apps/1240856775/appPricePoints?include=territory&filter%5Bterritory%5D=JPN&limit=5",
"next" : "https://api.appstoreconnect.apple.com/v1/apps/1240856775/appPricePoints?cursor=BQ.AMO4C2k&include=territory&filter%5Bterritory%5D=JPN&limit=5"
},
next
字段便是恳求下一页的恳求链接,假如开发者不想记载整个链接内容,能够只保存 表明下一页的游标的字段 cursor
值。
当然,奇葩的工作,Apple Server API 接口的分页逻辑是:hasMore
和 revision
或 paginationToken
,例如 “&paginationToken=45380b30-5ed1-11ed-8aba-e1f7e9604fd2"
,如此不统一的接口恳求方法,充分阐明这肯定是两个团队在搞事!
2.3 获取某个 app 的价格点的信息(Read app price point information)
留意这个接口需求的 {id}
参数,是 App 的价格点接口获取到的价格点 id,例如 eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ
。
GET https://api.appstoreconnect.apple.com/v3/appPricePoints/{id}?include=app,territory
默许恳求回来的内容:
{
"data": {
"type": "appPricePoints",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ",
"attributes": {
"customerPrice": "1.0",
"proceeds": "0.84"
}
}
}
加上参数 ?include=app,territory
才能获取到对应的国家或区域码,比方价格点人民币 1.0 元,对应的 id :
{
"type" : "appPricePoints",
"id" : "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ",
"attributes" : {
"customerPrice" : "1.0",
"proceeds" : "0.84"
},
"relationships" : {
"territory" : {
"data" : {
"type" : "territories",
"id" : "CHN"
}
}
}
}
这个接口的作用是便利依据某个价格点,反查货币品种和 app 信息等。别的有 100 个高价格不是一切 app 默许支撑,所以经过反查能够获取 app 信息。
2.4 某个价格点对应的174个国家或区域的均衡价格(List app price point equalizations)
留意这个接口的 {id}
参数,也是 App 的价格点接口获取到的价格点 id。
GET https://api.appstoreconnect.apple.com/v3/appPricePoints/{id}/equalizations?include=app,territory
回来的内容示例:
{
"type": "appPricePoints",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJBRkciLCJwIjoiMTAwMTAifQ",
"attributes": {
"customerPrice": "0.99",
"proceeds": "0.84"
},
"relationships": {
"app": {
"data": {
"type": "apps",
"id": "1240856775"
}
},
"territory": {
"data": {
"type": "territories",
"id": "AFG"
}
}
}
}
回来的是剩余 174 个国家或区域的对应价格点的均衡价格。
留意:这个接口是 app 的全球均衡价格点查询,IAP 内购的接口暂时未发现苹果有供给,但 v2.0 版别苹果供给了订阅产品的全球均衡价格点接口:List All Subscription Price Point Equalizations。
2.5 获取内购 IAP 的价格点(List all price points for an in-app purchase)
GET https://api.appstoreconnect.apple.com/v2/inAppPurchases/{id}/pricePoints?filter[territory]=CHN&include=territory&limit=200
留意接口的 {id}
是内购产品 id,能够经过接口 List All In-App Purchases for an App 获取某个 app 的一切 IAP id。
字段 filter[territory]=CHN,USA
拼接多个字段,这时能够回来多个区域的价格点。别的,假如需求知道回来的价格点是那个国家或区域的,需求带上 include=territory
,不然不会显示国家或区域码。
终究回来的内容示例:
{
"type": "inAppPurchasePricePoints",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ",
"attributes": {
"customerPrice": "1.0",
"proceeds": "0.84",
"priceTier": "10001"
},
"relationships": {
"territory": {
"data": {
"type": "territories",
"id": "CHN"
}
}
}
}
同时,这个接口回来 800 个价格点,100 个高价格点申请经过的 IAP 产品才支撑。别的IAP 内购产品没有 0.0
免费的价格点。
2.6 获取某个 app 的价格时刻表(App 等级)(Read price schedule information for an app)
GET https://api.appstoreconnect.apple.com/v1/apps/{id}/appPriceSchedule?include=app,automaticPrices,baseTerritory,manualPrices
回来内容:
{
"data": {
"type": "appPriceSchedules",
"id": "1240856775",
"relationships": {
"app": {
"data": {
"type": "apps",
"id": "1240856775"
}
},
"automaticPrices": {
"meta": {
"paging": {
"total": 170,
"limit": 10
}
},
"data": [
{
"type": "appPrices",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJBRkciLCJwIjoiMTAwMTAiLCJzZCI6MC4wLCJlZCI6MC4wfQ"
},
... 省掉 ...
... 省掉 ...
],
},
"manualPrices": {
"meta": {
"paging": {
"total": 8,
"limit": 10
}
},
"data": [
{
"type": "appPrices",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDEiLCJzZCI6MC4wLCJlZCI6MC4wfQ"
},
... 省掉 ...
... 省掉 ...
],
},
"baseTerritory": {
"data": {
"type": "territories",
"id": "CHN"
},
}
},
}
回来的内容包括 3 部分:
- automaticPrices:主动价格
- manualPrices:自定价格
- baseTerritory:基准国家
2.7 获取某个 app 的具体价格时刻表(App 等级)(Read an app’s price schedule information)
GET https://api.appstoreconnect.apple.com/v1/appPriceSchedules/{id}?include=app,automaticPrices,baseTerritory,manualPrices
这个接口回来内容与上一个接口相同,所以这儿省掉,暂时不明确为什么会这样。
2.8 获取某个 app 的全球均衡价格时刻表(App 等级)(List automatically generated prices for an app)
GET https://api.appstoreconnect.apple.com/v1/appPriceSchedules/{id}/automaticPrices?include=appPricePoint,territory&limit=200
回来内容,示例:我国香港的价格设置为手动调整价格,且价格于 2023 年 4 月 20 日完毕,系统就变成“主动调整”:
{
"type" : "appPrices",
"id" : "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJIS0ciLCJwIjoiMTAwMDciLCJzZCI6MTY4MTk3NDAwMC4wMDAwMDAwMDAsImVkIjowLjB9",
"attributes" : {
"manual" : false,
"startDate" : "2023-04-20",
"endDate" : null
},
"relationships" : {
"appPricePoint" : {
"data" : {
"type" : "appPricePoints",
"id" : "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJIS0ciLCJwIjoiMTAwMDcifQ"
}
},
"territory" : {
"data" : {
"type" : "territories",
"id" : "HKG"
}
}
},
}
留意:经过开始时刻和完毕时刻,有可能总的条数 total 超越 174 个国家或区域。还有外汇汇率或税率调整等要素。全球均衡价格时刻表比较杂乱,我们能够自己在 ASC 后台装备不同价格规则,然后观察接口回来的内容。
2.9 获取某个 app 的自定价格时刻表(App 等级)(List manually chosen prices for an app)
https://api.appstoreconnect.apple.com/v1/appPriceSchedules/{id}/manualPrices?include=appPricePoint,territory&limit=200
呼应内容示例:
{
"type": "appPrices",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJBVVMiLCJwIjoiMTAwMjIiLCJzZCI6MTY4MjQ5MjQwMC4wMDAwMDAwMDAsImVkIjoxNjgyODM4MDAwLjAwMDAwMDAwMH0",
"attributes": {
"manual": true,
"startDate": "2023-04-26",
"endDate": "2023-04-30"
},
"relationships": {
"appPricePoint": {
"data": {
"type": "appPricePoints",
"id": "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJBVVMiLCJwIjoiMTAwMjIifQ"
}
},
"territory": {
"data": {
"type": "territories",
"id": "AUS"
}
}
}
}
2.10 获取某个 app 的基准国家(App 等级)(Read the base territory for an app’s price schedule)
GET https://api.appstoreconnect.apple.com/v1/appPriceSchedules/{id}/baseTerritory
呼应内容示例:
{
"data": {
"type": "territories",
"id": "CHN",
"attributes": {
"currency": "CNY"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/CHN"
}
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/appPriceSchedules/1240856775/baseTerritory"
}
}
假如没有设置基准国家的新 app,默许是美国为基准国家:
{
"data" : {
"type" : "territories",
"id" : "USA",
"attributes" : {
"currency" : "USD"
},
"links" : {
"self" : "https://api.appstoreconnect.apple.com/v1/territories/USA"
}
},
"links" : {
"self" : "https://api.appstoreconnect.apple.com/v1/appPriceSchedules/6446581591/baseTerritory"
}
}
2.11 设定某个 app 的价格调整(App 等级)(Add a scheduled price change to an app)
POST https://api.appstoreconnect.apple.com/v1/appPriceSchedules
恳求体:
#基准国家
base_territory_id = "CHN"
base_territory_id2 = "HKG"
app_price_id = "随意姓名,用于区别一个价格方案"
# 全球均衡价格
app_price_point_id = "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ" # CNY¥ 1.00
app_price_point_id2 = "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJDSE4iLCJwIjoiMTAwMDUifQ" # CNY¥ 2.50
# 自定价格
app_price_point_id3 = "eyJzIjoiMTI0MDg1Njc3NSIsInQiOiJIS0ciLCJwIjoiMTAwMTUifQ" # HKD $16.00
# 恳求体
body = {
'data': {
'relationships': {
'app': {
'data': {
'id': f"{app_id}",
'type': 'apps'
}
},
'baseTerritory': {
'data': {
'id': f"{base_territory_id}",
'type': 'territories'
}
},
'manualPrices': {
'data': [
{
'id': f"{app_price_id}",
'type': 'appPrices'
},
{
'id': f"{app_price_id}2",
'type': 'appPrices'
},
{
'id': f"{app_price_id}3",
'type': 'appPrices'
}
]
}
},
'type': 'appPriceSchedules'
},
'included': [
{
'id': f'{app_price_id}',
'type': 'appPrices',
'attributes': {
'startDate': '2023-04-25',
'endDate': None
},
'relationships': {
'appPricePoint': {
'data': {
'id': f"{app_price_point_id}",
'type': 'appPricePoints'
}
}
}
},
{
'id': f'{app_price_id}2',
'type': 'appPrices',
'attributes': {
'startDate': None,
'endDate': '2023-04-25'
},
'relationships': {
'appPricePoint': {
'data': {
'id': f"{app_price_point_id2}",
'type': 'appPricePoints'
}
}
}
},
{
'id': f'{app_price_id}3',
'type': 'appPrices',
'attributes': {
'startDate': None, # '2023-04-14',
'endDate': None
},
'relationships': {
'appPricePoint': {
'data': {
'id': f"{app_price_point_id3}",
'type': 'appPricePoints'
}
}
}
}
]
}
关于这个恳求的参数和解析,请参阅本文的 2.16 章节《2.16 设定某个 IAP 的价格调整(IAP 等级)(Add a scheduled price change to an in-app purchase)》,由于恳求相同,所以统一在后文中解析。
2.12 获取某个 IAP 的价格时刻表(IAP 等级)(Read price information for an in-app purchase price schedule)
注: 这个接口是 v2.0 版别就有,从查询到的内容来看,回来的仅仅 manualPrices
自定价格的信息。
GET https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules/{id}/manualPrices?include=inAppPurchasePricePoint,territory
呼应示例:
{
"type": "inAppPurchasePrices",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMSIsInNkIjowLjAsImVkIjowLjB9",
"attributes": {
"startDate": null,
"endDate": null,
"manual": true
},
"relationships": {
"inAppPurchasePricePoint": {
"data": {
"type": "inAppPurchasePricePoints",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMSJ9"
}
},
"territory": {
"data": {
"type": "territories",
"id": "CHN"
}
}
}
}
2.13 获取某个 IAP 的具体价格时刻表(IAP 等级)(Read in-app purchase price schedule information)
注: 这个接口是 v2.0 版别就有,回来的内容包括基准国家、全球均衡国家和自定价格的时刻表。
GET https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules/{id}?include=automaticPrices,baseTerritory,manualPrices
呼应示例:
{
"type": "inAppPurchasePriceSchedules",
"id": "6444653105",
"relationships": {
"baseTerritory": {
"data": {
"type": "territories",
"id": "CHN"
}
},
"manualPrices": {
"meta": {
"paging": {
"total": 1,
"limit": 10
}
},
"data": [
{
"type": "inAppPurchasePrices",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMSIsInNkIjowLjAsImVkIjowLjB9"
}
]
},
"automaticPrices": {
"meta": {
"paging": {
"total": 348,
"limit": 10
}
},
"data": [
{
"type": "inAppPurchasePrices",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJBRkciLCJwIjoiMSIsInNkIjowLjAsImVkIjoxNjgzNjE1NjAwLjAwMDAwMDAwMH0"
},
... 省掉 ...
... 省掉 ...
]
}
}
}
2.14 获取某个 IAP 的全球均衡价格时刻表(IAP 等级)(List automatically generated prices for an in-app purchase price)
GET https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules/{id}/automaticPrices?include=inAppPurchasePricePoint,territory&limit=200
呼应示例:
{
"type": "inAppPurchasePrices",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJBRkciLCJwIjoiMSIsInNkIjowLjAsImVkIjoxNjgzNjE1NjAwLjAwMDAwMDAwMH0",
"attributes": {
"startDate": null,
"endDate": "2023-05-09",
"manual": false
},
"relationships": {
"inAppPurchasePricePoint": {
"data": {
"type": "inAppPurchasePricePoints",
"id": "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJBRkciLCJwIjoiMSJ9"
}
},
"territory": {
"data": {
"type": "territories",
"id": "AFG"
}
}
}
},
2.15 获取某个 IAP 的基准国家(IAP 等级)(Read the selected base territory for an in-app purchase price schedule)
GET https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules/{id}/baseTerritory
呼应示例:
{
"data": {
"type": "territories",
"id": "CHN",
"attributes": {
"currency": "CNY"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/CHN"
}
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules/6444653105/baseTerritory"
}
}
2.16 设定某个 IAP 的价格调整(IAP 等级)(Add a scheduled price change to an in-app purchase)
注: 这个接口是 v2.0 版别就有,是原有装备 IAP 内购价格的接口,苹果在原接口的基础上,添加了字段 baseTerritory
表明基准国家。
POST https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules
恳求体:
{
'data': {
'relationships': {
'inAppPurchase': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
},
'baseTerritory': {
'data': {
'id': f"{base_territory_id}",
'type': 'territories'
}
},
'manualPrices': {
'data': [
{
'id': f'{iap_price_id}',
'type': 'inAppPurchasePrices'
}
]
}
},
'type': 'inAppPurchasePriceSchedules'
},
'included': [
{
'id': f'{iap_price_id}',
'type': 'inAppPurchasePrices',
'attributes': {
'startDate': None, # '2023-04-14',
'endDate': None
},
'relationships': {
'inAppPurchasePricePoint': {
'data': {
'id': f"{iap_price_point_id}",
'type': 'inAppPurchasePricePoints'
}
},
'inAppPurchaseV2': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
}
}
}
]
}
其间的恳求字段的意义:
-
app_iap_id
:内购产品的标识 id,ASC 后台叫Apple ID
,如6444653105
-
base_territory_id
:基准国家或区域,例如我国大陆,CHN
,我国香港HKG
-
iap_price_id
:随意姓名,用于区别一个价格方案,如我是1.00人民币方案
-
iap_price_point_id
:经过内购价格点列表(本文章节 2.5 获取内购 IAP 的价格点)获取,如 CNY¥ 1.00 的价格点 id 是 “eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ”。
上面的恳求,是表明设置基准国家,而且设置全球均衡价格,留意,这儿默许设置全球一切的国家和区域。假如是想某个国家或区域设置自定价格,恳求示例:
#基准国家
base_territory_id = "CHN"
base_territory_id2 = "HKG"
iap_price_id = "随意姓名,用于区别一个价格方案"
# 全球均衡价格
iap_price_point_id = "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMTAwMDEifQ" # CNY¥ 1.00
iap_price_point_id2 = "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJDSE4iLCJwIjoiMTAwMDUifQ" # CNY¥ 2.50
# 自定价格
iap_price_point_id3 = "eyJzIjoiNjQ0NDY1MzEwNSIsInQiOiJIS0ciLCJwIjoiMTAwMTUifQ" # HKD $16.00
# 恳求体
body = {
'data': {
'relationships': {
'inAppPurchase': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
},
'baseTerritory': {
'data': {
'id': f"{base_territory_id}",
'type': 'territories'
}
},
'manualPrices': {
'data': [
{
'id': f'{iap_price_id}',
'type': 'inAppPurchasePrices'
},
{
'id': f"{iap_price_id}2",
'type': 'inAppPurchasePrices'
},
{
'id': f"{iap_price_id}3",
'type': 'inAppPurchasePrices'
}
]
}
},
'type': 'inAppPurchasePriceSchedules'
},
'included': [
{
'id': f'{iap_price_id}',
'type': 'inAppPurchasePrices',
'attributes': {
'startDate': '2023-04-25',
'endDate': None
},
'relationships': {
'inAppPurchasePricePoint': {
'data': {
'id': f"{iap_price_point_id}",
'type': 'inAppPurchasePricePoints'
}
},
'inAppPurchaseV2': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
}
}
},
{
'id': f'{iap_price_id}2',
'type': 'inAppPurchasePrices',
'attributes': {
'startDate': None,
'endDate': '2023-04-25'
},
'relationships': {
'inAppPurchasePricePoint': {
'data': {
'id': f"{iap_price_point_id2}",
'type': 'inAppPurchasePricePoints'
}
},
'inAppPurchaseV2': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
}
}
},
{
'id': f'{iap_price_id}3',
'type': 'inAppPurchasePrices',
'attributes': {
'startDate': None,
'endDate': None
},
'relationships': {
'inAppPurchasePricePoint': {
'data': {
'id': f"{iap_price_point_id3}",
'type': 'inAppPurchasePricePoints'
}
},
'inAppPurchaseV2': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
}
}
}
]
}
这个示例表明,以我国大陆 CHN
为基准国家,而且设置一切国家和区域都是主动全球均衡价格,除了我国香港 HKG
。然后从现在到 2023-04-25
,运用基准国家我国大陆的 CNY¥ 2.50
价格点设置全球均衡价格,从 2023-04-25
开始,运用基准国家我国大陆的 CNY¥ 1.00
价格点设置全球均衡价格。破例的是我国香港,从现在开始一直是手动调整 自定价格
HKD $16.00
,也便是固定价格,不跟从全球均衡价格调整。
这儿坑比较多,baseTerritory
基准国家字段有必要设置,不然会报错:
{
"errors" : [ {
"id" : "82b5ea44-b220-402b-b7b9-88031f76a115",
"status" : "409",
"code" : "ENTITY_ERROR.ATTRIBUTE.REQUIRED",
"title" : "The provided entity is missing a required field",
"detail" : "You must provide a value for the field (baseTerritory) with this request",
"source" : {
"pointer" : "/data/attributes/baseTerritory"
}
} ]
}
然后 manualPrices
字段虽然是手动价格的意思,但并不是自定价格的意思,表明一切需求设定的价格时刻表方案,这儿咱们设置了 3 个价格时刻方案:
'manualPrices': {
'data': [
{
'id': f'{iap_price_id}',
'type': 'inAppPurchasePrices'
},
{
'id': f"{iap_price_id}2",
'type': 'inAppPurchasePrices'
},
{
'id': f"{iap_price_id}3",
'type': 'inAppPurchasePrices'
}
]
}
上面的 id
表明价格时刻方案表的姓名,用于区别每个时刻方案表。然后接着,便是要列表具体的价格时刻表:
'included': [
{
'id': f'{iap_price_id}',
'type': 'inAppPurchasePrices',
'attributes': {
'startDate': '2023-04-25',
'endDate': None
},
'relationships': {
'inAppPurchasePricePoint': {
'data': {
'id': f"{iap_price_point_id}",
'type': 'inAppPurchasePricePoints'
}
},
'inAppPurchaseV2': {
'data': {
'id': f"{app_iap_id}",
'type': 'inAppPurchases'
}
}
}
},
... 省掉 ...
... 省掉 ...
]
这儿最杂乱的是 2 个地方,included.x.id
和 manualPrices.data.x.id
是一一对应,所以有一个价格时刻方案表,就有对应的一个 included.x.id
,它们跟 relationships.inAppPurchasePricePoint.data.id
是没有关联的,当然假如你觉得便利,把三者都设置为价格点的 id 也是能够。
留意 included.x.id
数组列出的价格时刻方案表,必然在 manualPrices.data.x.id
在列出,不然报错:
{
"errors" : [ {
"id" : "13b3b82d-ba4b-4fda-97e1-2c30a37bd729",
"status" : "409",
"code" : "ENTITY_ERROR.RELATIONSHIP.REQUIRED",
"title" : "The provided entity is missing a required relationship",
"detail" : "You must provide a value for the relationship 'inAppPurchasePricePoint' with this request",
"source" : {
"pointer" : "/included/3/relationships/inAppPurchasePricePoint"
}
} ]
}
relationships.inAppPurchasePricePoint.data.id
需求设置为对应需求的国家或区域的价格点 id,这儿是我国大陆,所以设置为 CHN
对应的价格点。而需求自定价格的国家或区域,则就需求设置对应国家或区域的价格点。(内购价格点列表:参阅本文章节 2.5 获取内购 IAP 的价格点)
别的需求留意,基准国家的价格时刻表的 startDate
和 endDate
,假如是有多个时刻方案表,则一定是需求包括一切的时刻段,不然会报错:
{
"errors" : [ {
"id" : "8ad9f644-bdb5-4eaf-9029-6b6451b68677",
"status" : "409",
"code" : "ENTITY_ERROR.INVALID_INTERVAL",
"title" : "There is a problem with the request entity",
"detail" : "Entire timeline must be covered for CHN. Adjacent intervals must not have a gap in between: [null - 2023-04-24T00:00] and [2023-04-25T00:00 - null]",
"source" : {
"pointer" : "/data/relationships/manualPrices"
}
} ]
}
最终,baseTerritory
基准国家对应的价格点是有必要设置,不然会报错:
{
"errors" : [ {
"id" : "4cb1ed03-fea8-467b-a9b0-a563087584f7",
"status" : "409",
"code" : "ENTITY_ERROR.BASE_TERRITORY_INTERVAL_REQUIRED",
"title" : "There is a problem with the request entity",
"detail" : "There must be at least one manual price for the base territory.",
"source" : {
"pointer" : "/data/relationships/manualPrices"
}
} ]
}
最终,还有一个留意事件,咱们这个例子中,基准国家我国大陆(CHN
)从现在到 2023-04-25
运用的 CNY¥ 2.50
价格点设置全球均衡价格,从 2023-04-25
开始,运用 CNY¥ 1.00
价格点设置全球均衡价格。破例的是我国香港,从现在开始一直是手动调整 自定价格
HKD $16.00
。但在苹果 ASC 后台展现的价格时刻表:
只有 22 个国家或区域,会跟从 2023-04-25
进行主动调整。剩余的 152 个国家或区域,由于基准国家的 CNY¥ 1.00
和 CNY¥ 2.50
对应的全球均衡价格都是相同的价格点,所以并不会随 2023-04-25
进行主动调整。这个需求留意,后续的苹果调价方案,还有外汇汇率或税率调整等要素的影响。
综上总结,设定某个 IAP 的价格调整(IAP 等级)的接口,有必要遵从的规则:
- 有必要设置
baseTerritory
基准国家 - 基准国家的价格点时刻方案表,必然包括一切的时刻段
- 假如是自定价格,则有必要一个一个国家的价格点列出,不能批量指定多个国家
- 自定价格的时刻方案表,能够只包括一个
startDate
或endDate
,或者都为空时的全时刻段。
2.17 获取某个 app 的出售规模(App 等级)(List availability for an app)
GET https://api.appstoreconnect.apple.com/v1/apps/{id}/appAvailability?include=app,availableTerritories
呼应示例:
{
"data": {
"type": "appAvailabilities",
"id": "1240856775",
"attributes": {
"availableInNewTerritories": true
},
"relationships": {
"app": {
"data": {
"type": "apps",
"id": "1240856775"
}
},
"availableTerritories": {
"meta": {
"paging": {
"total": 175,
"limit": 10
}
},
"data": [
{
"type": "territories",
"id": "USA"
},
{
"type": "territories",
"id": "FRA"
},
... 省掉 ...
... 省掉 ...
]
}
}
},
2.18 获取某个 app 的出售规模信息(App 等级)(Read the availability for an app)
GET https://api.appstoreconnect.apple.com/v1/appAvailabilities/{id}?include=app,availableTerritories
接口呼应与上一个接口相同,具体作用是否相同,暂时未发现区别。
2.19 获取某个 app 的出售规模列表(App 等级)(List territory availability for an app)
GET https://api.appstoreconnect.apple.com/v1/appAvailabilities/{id}/availableTerritories
呼应示例:
{
"data": [
{
"type": "territories",
"id": "USA",
"attributes": {
"currency": "USD"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/USA"
}
},
{
"type": "territories",
"id": "FRA",
"attributes": {
"currency": "EUR"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/FRA"
}
},
... 省掉 ...
... 省掉 ...
... 省掉 ...
}
2.20 修正某个 app 的出售规模(App 等级)(Modify territory availability for an app)
POST https://api.appstoreconnect.apple.com/v1/appAvailabilities
恳求体:
{
"data": {
"type": "appAvailabilities",
"attributes": {
"availableInNewTerritories": True
},
"relationships": {
"app": {
"data": {
"type": "apps",
"id": f"{app_id}"
}
},
"availableTerritories": {
"data": [
{
"type": "territories",
"id": "USA"
},
{
"type": "territories",
"id": "HKG"
},
{
"type": "territories",
"id": "CHN"
}
]
}
}
}
}
这个恳求比较简单,把需求出售的国家或区域放到 availableTerritories
下的 data
数组中就能够,不在 data
数组里的国家或区域,便是表明不支撑的区域。测验发现,恳求成功后,ASC 后台立刻收效。
2.21 获取某个 IAP 的出售规模(IAP 等级)(List the territory availablity of an in-app purchase)
GET https://api.appstoreconnect.apple.com/v1/inAppPurchaseAvailabilities/{id}/availableTerritories
呼应体:
{
"data": [
{
"type": "territories",
"id": "KOR",
"attributes": {
"currency": "KRW"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/KOR"
}
},
{
"type": "territories",
"id": "HKG",
"attributes": {
"currency": "HKD"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/territories/HKG"
}
},
... 省掉 ...
... 省掉 ...
... 省掉 ...
}
2.22 获取某个 IAP 的出售规模信息(IAP 等级)(Read the availablity of an in-app purchase)
GET https://api.appstoreconnect.apple.com/v1/inAppPurchaseAvailabilities/{id}?include=availableTerritories
呼应体:
{
"data": {
"type": "inAppPurchaseAvailabilities",
"id": "6444653105",
"attributes": {
"availableInNewTerritories": false
},
"relationships": {
"availableTerritories": {
"meta": {
"paging": {
"total": 6,
"limit": 10
}
},
"data": [
{
"type": "territories",
"id": "KOR"
},
... 省掉 ...
... 省掉 ...
],
}
}
},
}
2.23 修正某个 IAP 的出售规模(IAP 等级)(Modify the territory availablity of an in-app purchas)
POST https://api.appstoreconnect.apple.com/v1/inAppPurchaseAvailabilities
{
"data": {
"type": "inAppPurchaseAvailabilities",
"attributes": {
"availableInNewTerritories": True
},
"relationships": {
"availableTerritories": {
"data": [
{
"type": "territories",
"id": "USA"
},
{
"type": "territories",
"id": "CHN"
},
{
"type": "territories",
"id": "ISL"
}
]
},
"inAppPurchase": {
"data": {
"id": f"{app_iap_id}",
"type": "inAppPurchases"
}
}
}
}
}
这个恳求比较简单,把需求出售的国家或区域放到 availableTerritories
下的 data
数组中就能够,不在 data
数组里的国家或区域,便是表明不支撑的区域。测验发现,恳求成功后,ASC 后台立刻收效。
2.24 获取某个 subscription IAP 的出售规模(IAP 等级)(List the territory availability of a subscription)
GET https://api.appstoreconnect.apple.com/v1/subscriptionAvailabilities/{id}/availableTerritories
2.25 获取某个 subscription IAP 的出售规模信息(IAP 等级)(Read the availability of a subscription)
GET https://api.appstoreconnect.apple.com/v1/subscriptionAvailabilities/{id}?include=availableTerritories,subscription
2.26 修正某个 subscription IAP 的出售规模(IAP 等级)(Modify the territory availability of a subscription)
POST https://api.appstoreconnect.apple.com/v1/subscriptionAvailabilities
呼应体:
{
"data": {
"type": "subscriptionAvailabilities",
"attributes": {
"availableInNewTerritories": True
},
"relationships": {
"availableTerritories": {
"data": [
{
"type": "territories",
"id": "USA"
},
{
"type": "territories",
"id": "CHN"
},
{
"type": "territories",
"id": "ISL"
}
]
},
"subscription": {
"data": {
"id": f"{app_iap_id}",
"type": "subscriptions"
}
}
}
}
}
三、总结
文中的恳求示例是精简后的内容,具体的恳求示例(Python 代码实现)和恳求呼应内容,咱们放在 GitHub 库房 37iOS/AppStoreConnectAPI-Demo,后续 API 晋级都会一同更新,我们能够自行获取。
关于 API 恳求,需求考虑好分页的可能性,未来可能超越 175 个国家区域时的就需求分页,而对于全球均衡价格和自定价格等时刻表,有可能超出 200 个价格时刻表,所以肯定是需求考虑好分页处理。别的,咱们近期会更新苹果派 AppleParty 以支撑批量装备苹果新价格机制,敬请等待~
最终,苹果 App Store Connect API 文档的介绍依然有待提高,了解一个 API 的参数改变,都要重复几百次测验。最终,让咱们一同等待 2023 年 6 月苹果 WWDC23 带来更多改变吧~
欢迎我们评论区一同评论沟通~
欢迎关注咱们,了解更多 iOS 和 Apple 的动态~
参阅引用
- App Store Connect API version 2.3 release notes | Apple Developer Documentation
- App Store 新定价机制 – 2023年最全版 –
- 运用 App Store Connect API 批量创建内购产品 –
- WWDC21 – App Store Server API 实践总结 –
- 设置价格 – 办理 App 定价 – App Store Connect
- 设置 App 内购买项目的价格 – 办理 App 内购买项目 – App Store Connect