fastlane icon indicating copy to clipboard operation
fastlane copied to clipboard

[spaceship] Add get app availabilities v2 request

Open lucgrabowski opened this issue 11 months ago β€’ 9 comments

Checklist

  • [x] I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • [x] I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • [x] I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • [x] I've read the Contribution Guidelines
  • [x] I've updated the documentation if necessary.
  • [x] I've added or updated relevant unit tests.

Motivation and Context

As written in https://github.com/fastlane/fastlane/pull/21890, there is a need to implement a new request for app availabilities. It will allow for checking if app is available or removed from distribution. PR should be considered after https://github.com/fastlane/fastlane/pull/21900 is handled.

Description

In this PR a request for app availabilities (https://developer.apple.com/documentation/appstoreconnectapi/read_app_availablity_territories) is implemented. It's a first request to v2 version in path. Request is used in Pricing and Availability on AppStoreConnect.

Testing Steps

I added unit tests for models. I also tested the request in spaceship playground.

lucgrabowski avatar Feb 29 '24 15:02 lucgrabowski

question: how are you going to know which territory corresponds to a territoryAvailability?

shernade avatar Apr 16 '24 16:04 shernade

@shernade I took a look at the fixtures and I think that when you fetch appAvailabilities you can get territoryAvailabilities and as far as I remember ids are meaningful for them. If you want to know exactly how it works, you could login to AppstoreConnect in web browser with developer tools open and check network requests on "Pricing and Availability".

lucgrabowski avatar Apr 16 '24 20:04 lucgrabowski

i see that doing a call like this: client.tunes_request_client.get("v2/appAvailabilities/6497953632/territoryAvailabilities", client.tunes_request_client.build_params(filter: {}, includes: "territory", limit: 200 , sort: nil)) including territory the json data has territory info:

 =>
#<Spaceship::ConnectAPI::Response:0x00007f9abe72a2f8
 @body=
  {"data"=>
    [{"type"=>"territoryAvailabilities",
      "id"=>"eyJzIjoiNjQ5Nzk1MzYzMiIsInQiOiJEWkEifQ",
      "attributes"=>{"available"=>false, "availableInPast"=>false, "preOrderAvailableInPast"=>false, "releaseDate"=>nil, "preOrderEnabled"=>false, "preOrderPublishDate"=>nil, "contentStatuses"=>["CANNOT_SELL"]},
      "relationships"=>{"territory"=>{"data"=>{"type"=>"territories", "id"=>"DZA"}}},
      "links"=>{"self"=>"https://appstoreconnect.apple.com/iris/v1/territoryAvailabilities/eyJzIjoiNjQ5Nzk1MzYzMiIsInQiOiJEWkEifQ"}},
     {"type"=>"territoryAvailabilities",
      "id"=>"eyJzIjoiNjQ5Nzk1MzYzMiIsInQiOiJWRU4ifQ",
      "attributes"=>{"available"=>false, "availableInPast"=>false, "preOrderAvailableInPast"=>false, "releaseDate"=>nil, "preOrderEnabled"=>false, "preOrderPublishDate"=>nil, "contentStatuses"=>["CANNOT_SELL"]},
      "relationships"=>{"territory"=>{"data"=>{"type"=>"territories", "id"=>"VEN"}}},
      "links"=>{"self"=>"https://appstoreconnect.apple.com/iris/v1/territoryAvailabilities/eyJzIjoiNjQ5Nzk1MzYzMiIsInQiOiJWRU4ifQ"}},
     {"type"=>"territoryAvailabilities",

that model data seems a bit complicated to me, thanks

shernade avatar Apr 16 '24 20:04 shernade

@lucgrabowski Let's get https://github.com/fastlane/fastlane/pull/21900 through the door first. I hope tests are passing now. Then there should be less changes here, and hopefully less warnings.

Could you provide me/us with some basic steps to test/reproduce this with the Spaceship playground? More than happy to review that so we can get this PR here over the finish lines as well! Thanks for your work in the meantime :)

max-ott avatar May 03 '24 11:05 max-ott

https://github.com/fastlane/fastlane/pull/21900 Has been merged πŸ₯‡

jakub-przy avatar May 03 '24 14:05 jakub-przy

@max-ott Thanks for reviewing and merging other PRs. I don’t have an access to computer this weekend, but I have tried merging master through web interface, I hope it will be fine.

About testing steps in Spaceship playground. I logged in to developer account, fetched ConnectAPI::App and called get_app_availabitilites for this app. It’s also good to later check territory_availabilities for app availability. I used it in https://github.com/fastlane/fastlane/pull/21902

Also, using a network proxy may be useful and running playground with SPACESHIP_DEBUG=1 enabled, https://github.com/fastlane/fastlane/blob/master/spaceship/docs/Debugging.md)

lucgrabowski avatar May 04 '24 12:05 lucgrabowski

I have created my own fork with all the latest commits from master and then also applied the changes introduced in this PR - when running a test App Store deployment workflow - i'm still getting pretty much the same error:

> ************************/vendor/bundle/ruby/2.7.0/bundler/gems/fastlane_fork-e8fe2a941102/spaceship/lib/spaceship/connect_api/api_client.rb:223:in `handle_response': \e[31m[!] The provided entity includes an unknown attribute - 'availableInNewTerritories' is not an attribute on the resource 'apps' - /data/attributes/availableInNewTerritories (Spaceship::UnexpectedResponse)
> The provided entity includes an unknown relationship - 'prices' is not a relationship on the resource 'apps' - /data/relationships/prices
> The provided entity includes an unknown relationship - 'availableTerritories' is not a relationship on the resource 'apps' - /data/relationships/availableTerritories\e[0m

I just thought you'd like to know

jakub-przy avatar May 08 '24 11:05 jakub-przy

I think the problem is that you can only retrieve (get) the availabilities if they are already set. If they are empty, e.g. for a new app, there will be an error. I'm not 100% sure how other spaceship methods handle this. Ideally we would be able to get but also set / update the availabilities.

My test:

// login first
app = Spaceship::ConnectAPI::App.get(app_id: "123456789")
app.get_app_availabilities

Results

.../fastlane-2f8d1a77ff58/spaceship/lib/spaceship/connect_api/api_client.rb:223:in `handle_response': The specified resource does not exist - There is no resource of type 'appAvailabilities' with id '123456789' (Spaceship::UnexpectedResponse)
	from .../fastlane-2f8d1a77ff58/spaceship/lib/spaceship/connect_api/api_client.rb:114:in `get'
	from .../fastlane-2f8d1a77ff58/spaceship/lib/spaceship/connect_api/tunes/tunes.rb:425:in `get_app_availabilities'
	from .../forwardable.rb:240:in `get_app_availabilities'
	from .../fastlane-2f8d1a77ff58/spaceship/lib/spaceship/connect_api/models/app.rb:157:in `get_app_availabilities'
	from (irb):7:in `<main>'
...
	```

It works just fine for apps that already have set availabilities.

max-ott avatar May 08 '24 12:05 max-ott

@max-ott You were absolutely right - it works! I guess we're gonna have to set those capabilities manually until a proper fix is in place. Still, this is great, cheers!

jakub-przy avatar May 08 '24 13:05 jakub-przy

Hello πŸ‘‹ Is there any news? The implementation of @lucgrabowski seems to be working correctly

Hantex9 avatar Jun 10 '24 23:06 Hantex9

When I try to submit an app using your branche I still get the response of; [!] The provided entity includes an unknown attribute - 'availableInNewTerritories' is not an attribute on the resource 'apps' - /data/attributes/availableInNewTerritories (Spaceship::UnexpectedResponse)

bkrijgsman avatar Jun 13 '24 14:06 bkrijgsman

@bkrijgsman Please keep in mind that this is only to retrieve the territories. If you have not previously set it, you will get this error message.

max-ott avatar Jun 13 '24 15:06 max-ott

@bkrijgsman Please keep in mind that this is only to retrieve the territories. If you have not previously set it, you will get this error message.

Ah check thanks.

Well if there is somehow who is good into this and can fix again that pricing & territories can be set from zero; would be very great. Maybe I can get a reward from my company, since this issue is now blocking our build street for some weeks.

bkrijgsman avatar Jun 13 '24 15:06 bkrijgsman

Ah check thanks.

Well if there is somehow who is good into this and can fix again that pricing & territories can be set from zero; would be very great. Maybe I can get a reward from my company, since this issue is now blocking our build street for some weeks.

@bkrijgsman

Similar situation here. Basically, now we're doing that initial part of the set-up manually, and then everything else is automated. Not as much of a pain as we initially thought (just 1-2 mins of manual work per workflow) but certainly not ideal.

jakub-przy avatar Jun 17 '24 08:06 jakub-przy

Sorry kind of new to this. Is there any news on when this will. be available on deliver action?

france-workmail avatar Jun 20 '24 17:06 france-workmail

@lucgrabowski can you show me an example of how can i set the app availability and pricing using spaceship? the app availabilities are already manually set, i just need to update them

muhammad67uzair avatar Jun 24 '24 06:06 muhammad67uzair

@muhammad67uzair Please read through the thread. This functionality is only for retrieving set availabilities. Locking this thread to prevent non relevant discussions.

max-ott avatar Jun 24 '24 08:06 max-ott