我正在构建一个脚本来通过 fastlane 上传新应用程序以进行存储。然而,fastlane 目前面临着为新创建的应用程序设置价格的问题。所以我创建了 ruby 脚本来通过 api 手动完成此操作。
我做的第一件事是在这个appstore文档的帮助下获取我的应用程序的价格点。我能够获得 0 美元的价格点,我想将其设置为我的应用程序的价格。我向此端点使用了补丁请求,但我无法这样做。
这是我的脚本的更新,如果有人可以指出我正确的方向。
lane :setAppPrice do
auth_token = authAppstoreAPI()
puts "Token: #{auth_token}"
app_id = 'app_id_here'
price_point_id = get_app_price_points(auth_token: auth_token, app_id: app_id)
if price_point_id
url = URI("https://api.appstoreconnect.apple.com/v1/#{app_id}/appPricePoints/#{price_point_id}")
# Create the HTTP request for updating the app price
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
# Prepare the PATCH request
headers = {
"Authorization" => "Bearer #{auth_token}",
"Content-Type" => "application/json"
}
request = Net::HTTP::Patch.new(url, headers)
# Prepare the body with the new price data
request.body = {
data: {
id: price_point_id,
type: "appPricePoints",
attributes: {
customerPrice: 0.0 # Set your desired new price here
}
}
}.to_json
# Execute the request
response = http.request(request)
# Handle the response
if response.code == "200"
UI.success("Successfully updated app price to 0.0 for price point ID #{price_point_id}")
else
UI.error("Failed to update app price: #{response.body}")
end
end
end
lane :get_app_price_points do |options|
require 'json'
require 'net/http'
auth_token = options[:auth_token] # Your App Store Connect API token
app_id = options[:app_id] # The app ID for which you want to list subscriptions
# Define the URL for fetching subscriptions
url = URI("https://api.appstoreconnect.apple.com/v1/apps/#{app_id}/appPricePoints?filter%5Bterritory%5D=USA,CAN&include=territory")
# Create the HTTP request
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
# Set up headers for the App Store Connect API request
headers = {
"Authorization" => "Bearer #{auth_token}",
"Content-Type" => "application/json"
}
# Prepare the GET request
request = Net::HTTP::Get.new(url, headers)
# Execute the request
response = http.request(request)
# Handle the response
if response.code == "200"
app_prices = JSON.parse(response.body)
# UI.message("Subscriptions for app #{app_id}: #{response.body}")
# Use the find method to get the free price point ID directly
free_price_point = app_prices["data"].find do |price_point|
price_point["attributes"]["customerPrice"] == "0.0"
end
free_price_point_id = free_price_point ? free_price_point["id"] : nil
UI.message("Free Price Point ID: #{free_price_point_id}")
# Return the ID of the price point with 0.0 price
free_price_point_id
else
UI.error("Failed to fetch subscriptions: #{response.body}")
end
end