使用 App Store Connect API v2.3 管理 App Store 新定价机制

作者: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 仓库:

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 接口的分页逻辑是:hasMorerevisionpaginationToken,例如 “&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"
                    },
                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值