LoginSignup
11
12

More than 3 years have passed since last update.

App Store Connect APIの叩き方

Last updated at Posted at 2018-11-12

APIの叩き方概要

App Store Connect APIは App Store Connectの「ユーザーとアクセス」の「キー」から発行、DLしたキーをJWT(JSON Web Tokens)でアカウントを認証する。権限がない場合は「キー」タブは表示されない。

ちなみにこのキーは1度しかDLできない。
詳細:https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api

以下、具体的手順

App Store Connect API

ユーザとアクセスからキーを発行する

発行できる権限を持ったアカウントで発行(現在は個人アカウントではリクエストするのみ)

JWTを使用してtokenを発行する処理を書く

作成するJWTには以下の内容が必要
・JWT header
・JWT payload
・JWTの署名

tokenを発行する
WWDCの動画にもあるrubyで記述
jwtがない場合は事前に入れる(https://qiita.com/oshou/items/6283c2315dc7dd244aef からの gem 'jwt'を追加+bundle install)

token.rb

require "base64"
require "jwt"
ISSUER_ID = ""
KEY_ID = ""
private_key = OpenSSL::PKey.read(File.read("p8ファイルのアドレス/hoge.p8"))

token = JWT.encode(
   {
    iss: ISSUER_ID,
    exp: Time.now.to_i + 20 * 60,
    aud: "appstoreconnect-v1"
   },
   private_key,
   "ES256",
   header_fields={
     kid: KEY_ID }
 )
puts token

ISSURE_ID, KEY_ID,p8ファイルのアドレスを入力する.

上記を実行するとtokenが発行できます
ruby token.rb

tokenの期限が切れるまでに叩く

curl https://api.appstoreconnect.apple.com/v1/apps -H "Authorization: Bearer 発行したトークン"

これで叩けます。

期限切れになると以下のように返ってくる。

{
    "errors": [{
        "status": "401",
        "code": "NOT_AUTHORIZED",
        "title": "Authentication credentials are missing or invalid.",
        "detail": "Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens"
    }]
}

現時点ではまだprovisioningなどができないため(404が返ってきてしまう)のでアップデートに期待

参考: 

WWDC動画
https://developer.apple.com/videos/play/wwdc2018/303/ (後半のDEMOの部分が分かりやすいです

App Store Connect API
https://developer.apple.com/documentation/appstoreconnectapi

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12