Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Creating new edit failed! #15

Open
mohammedbabelly opened this issue Sep 12, 2022 · 38 comments
Open

Creating new edit failed! #15

mohammedbabelly opened this issue Sep 12, 2022 · 38 comments
Assignees
Labels
bug Something isn't working

Comments

@mohammedbabelly
Copy link

Hey there,
I'm using the lane like this:

    amazon_app_submission(
    client_id: "#{ENV["CLIENT_ID"]}",
    client_secret: "#{ENV["CLIENT_SECRET"]}",
    app_id: "#{ENV["APP_ID"]}",
    # Optional
    apk_path: "./app/build/outputs/apk/release/app-release.apk",
    upload_apk: true,
    submit_for_review: true
  )

But it's failing because of the Edit creation.

[09:57:22]: -----------------------------------
[09:57:22]: --- Step: amazon_app_submission ---
[09:57:22]: -----------------------------------
[09:57:22]: The amazon_app_submission plugin is working!
[09:57:22]: Fetching app access token
[09:57:22]: Getting current edit
[09:57:22]: Current edit not found, creating a new edit
[09:57:23]: Creating new edit failed!
@mohammedbabelly
Copy link
Author

Maybe because my app is under review, is it related? @mohammedhemaid

@FlaShG
Copy link
Contributor

FlaShG commented Sep 13, 2022

We had the same error now. We did not have an app under review at the time.

@mohammedhemaid
Copy link
Contributor

I think it starts happening after the latest update, please try to use the previous version 0.3.0 and see if is still happening.
I will check it and will let you know

@mohammedbabelly
Copy link
Author

I think it starts happening after the latest update, please try to use the previous version 0.3.0 and see if is still happening. I will check it and will let you know

Ok, I'll try to use the previous version, but just so I know: can I create a new edit and upload a new version if my app is not accepted yet (under review or not submitted yet)?

@mohammedhemaid mohammedhemaid self-assigned this Sep 13, 2022
@mohammedhemaid mohammedhemaid added the bug Something isn't working label Sep 13, 2022
@mohammedbabelly
Copy link
Author

How can I install an older version of the plugin directly using fastlnane add_plugin?
or should I find the path of the installed one and replace the files manually?

@mohammedhemaid
Copy link
Contributor

mohammedhemaid commented Sep 13, 2022

you can install it by this gem "fastlane-plugin-amazon_app_submission", "0.3.0"
or if you are using it locally you can write in the command line, git checkout 0.3.0 and use that version

@mohammedhemaid
Copy link
Contributor

I created a quick test to see why it failing but I got a 503 error, it seems like there is an issue in Amazon servers, the plugin will work if we restart the build.
seems like an issue with Amazon as we didn't change the logic of the create edit

@FlaShG
Copy link
Contributor

FlaShG commented Sep 13, 2022

Is it possible that Amazon needs a minute after creating an edit before it becomes available?
Either way, the docs state that

The successful response to [the create_edit] request includes the editId of the Edit.

So this should be used instead of starting an additional request to get the edit id.

@mohammedbabelly
Copy link
Author

I'm having these issues when using the 0.3.0 version.

C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-plugin-amazon_app_submission-0.3.0/lib/fastlane/plugin/amazon_app_submission/helper/amazon_app_submission_helper.rb:88:in `get_current_apk_id': \e[31m[!] undefined method `[]' for nil:NilClass (NoMethodError)

        apk_id = firstAPK['id']
                         ^^^^^^\e[0m
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-plugin-amazon_app_submission-0.3.0/lib/fastlane/plugin/amazon_app_submission/actions/amazon_app_submission_action.rb:26:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:229:in `chdir'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:157:in `trigger_action_by_name'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/fast_file.rb:159:in `method_missing'
        from Fastfile:102:in `block (2 levels) in parsing_binding'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/lane.rb:33:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:49:in `block in execute'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:45:in `chdir'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/runner.rb:45:in `execute'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/lane_manager.rb:47:in `cruise_lane'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/command_line_handler.rb:36:in `handle'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/commands_generator.rb:110:in `block (2 levels) in run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/commander-4.6.0/lib/commander/command.rb:187:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/commander-4.6.0/lib/commander/command.rb:157:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/commander-4.6.0/lib/commander/runner.rb:444:in `run_active_command'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:124:in `run!'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/commander-4.6.0/lib/commander/delegates.rb:18:in `run!'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/commands_generator.rb:354:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/commands_generator.rb:43:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/fastlane/lib/fastlane/cli_tools_distributor.rb:123:in `take_off'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-2.206.2/bin/fastlane:23:in `<top (required)>'
        from C:/Ruby31-x64/bin/fastlane:32:in `load'
        from C:/Ruby31-x64/bin/fastlane:32:in `<main>'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/fastlane-plugin-amazon_app_submission-0.3.0/lib/fastlane/plugin/amazon_app_submission/helper/amazon_app_submission_helper.rb:88:in `get_current_apk_id': undefined method `[]' for nil:NilClass (NoMethodError)

        apk_id = firstAPK['id']
                         ^^^^^^

@FlaShG
Copy link
Contributor

FlaShG commented Sep 13, 2022

@mohammedbabelly Yes, that is a known issue that was fixed with 0.4.0.
@mohammedhemaid 0.3.0 is not really an option as you can see 😅

@mohammedbabelly
Copy link
Author

@mohammedbabelly Yes, that is a known issue that was fixed with 0.4.0.
@mohammedhemaid 0.3.0 is not really an option as you can see 😅

Ok then, I'll wait until you fix this issue guys 🙂

@mohammedhemaid
Copy link
Contributor

@FlaShG
Actually what is failing is the create new edit request, so no edit is getting created and returns 503 error code
Also, we must use the open edit request so we get the ETag of the edit and replace the APK, I am pretty sure the issue is in Amazon server side, but I will keep investigating

@FlaShG
Copy link
Contributor

FlaShG commented Sep 13, 2022

I see. I'd suppose it's worth checking out whether the create_edit response doesn't also contain the ETag in the header, but that's another story then.

@mohammedhemaid
Copy link
Contributor

mohammedhemaid commented Sep 13, 2022

@FlaShG unfortunately, it doesn't have it. Actually, I spend about one week trying to figure out which ETag I should use and how to get it, as that wasn't clear in the docs.
I was using the ETag from create_edit and that wasn't the ETag that we should use, we should open the current edit to get the ETag hahaha.
but the problem now is the create_edit request is failing not the open_edit

@FlaShG
Copy link
Contributor

FlaShG commented Sep 13, 2022

Woof... I see 😄
All I could find out so far is this:
We currently have an upcoming version under review, so Amazon denying a new version seems sensible. In that state, we get
#<Net::HTTPServiceUnavailable 503 Service Unavailable readbody=true>
as the response object, and
#<Net::HTTPPreconditionFailed 412 Precondition Failed readbody=true>
as the response.header object. It might make sense to make the plugin more verbose about that. But a 503 response seems to be intended for this case. I am currently unable to delete our upcoming version to investigate further.

@mohammedhemaid
Copy link
Contributor

Ohh, that makes sense. seems that they are updating the API, tbh Amazon app store was one of the worst APIs I worked with, it's not stable and the documentation is not clear

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

So, this plugin is not working for now? @mohammedhemaid

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

This is the log I get

[15:33:58]: --- Step: amazon_app_submission ---
[15:33:58]: -----------------------------------
[15:33:58]: The amazon_app_submission plugin is working!
[15:33:58]: Fetching app access token
[15:33:59]: Getting current edit
[15:34:00]: Current edit not found, creating a new edit
[15:34:06]: Get current apk id
[15:34:08]: Get current apk ETag
[15:34:31]: Replacing the apk with apk from /Users/kahero/builds/ssPBrYgL/0/kahero-team/pos/build/app/outputs/flutter-apk/app-release.apk
[15:35:07]: Updating the changelogs
[15:35:16]: Amazon app submission failed at replacing the apk error code 400 and error respones {"httpCode"=>400, "message"=>"Bad Request", "errors"=>[{"errorCode"=>"required_data_absent", "errorMessage"=>"If-Match header is required"}]}```

@mohammedhemaid
Copy link
Contributor

Hi @ccfiel
if you want to submit your app for review automatically you have to provide a folder link that contains the change logs files for the languages you want to support then submit for review will work.
Please check the readme file for more details

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

@mohammedhemaid yes, I already did that, this is my fastlane config. Is there any I miss out?

  desc "Deploy to the Amazon app store"
  lane :amazon_app_store do
    amazon_app_submission(
      client_id: "amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxxxxx",
      client_secret: "c72e9a60413727bba04be8c26xxxxxxxxxxxxxxxxxxxxxxxxx",
      app_id: "amzn1.devportal.mobileapp.xxxxxxx",
      apk_path: "/Users/kahero/builds/ssPBrYgL/0/kahero-team/pos/build/app/outputs/flutter-apk/app-release.apk",
      changelogs_path:  "/Users/kahero/builds/ssPBrYgL/0/kahero-team/pos/",
      upload_changelogs: true,
      submit_for_review: true,
      upload_apk: true
    )
  end

@mohammedhemaid
Copy link
Contributor

@ccfiel can you please try to remove the / at the end of changelogs_path and make sure that the path is pointing to a folder that has the change logs file?
Also, is this the first time you are publishing this app to the store?

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

Ok, I will remove the / and get report back to you the result. No, this is not the first time. @mohammedhemaid

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

@mohammedhemaid still the same error. I am user version 0.4.0

[16:36:34]: ------------------------------
[16:36:34]: --- Step: default_platform ---
[16:36:34]: ------------------------------
[16:36:34]: Driving the lane 'android amazon_app_store' 🚀
[16:36:34]: -----------------------------------
[16:36:34]: --- Step: amazon_app_submission ---
[16:36:34]: -----------------------------------
[16:36:34]: The amazon_app_submission plugin is working!
[16:36:34]: Fetching app access token
[16:36:35]: Getting current edit
[16:36:37]: Current edit not found, creating a new edit
[16:37:00]: Creating new edit failed!

my new config

  desc "Deploy to the Amazon app store"
  lane :amazon_app_store do
    amazon_app_submission(
      client_id: "amzn1.application-oa2-client.ssds73exxxxxxxxxxxxxxxx",
      client_secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      app_id: "amzn1.devportal.mobileapp.xxxxxxxxxxxxxxxxxxxxx",
      apk_path: "/Users/kahero/builds/ssPBrYgL/0/kahero-team/pos/build/app/outputs/flutter-apk/app-release.apk",
      changelogs_path:  "/Users/kahero/builds/ssPBrYgL/0/kahero-team/pos",
      upload_changelogs: true,
      submit_for_review: true,
      upload_apk: true
    )
  end

@mohammedhemaid
Copy link
Contributor

@ccfiel the Creating new edit failed! is actually an issue in Amazon servers it returns 503 error and we are waiting for a fix for them in the next couple of days and if they didn't fix that we will create an issue, for now you have to restart the plugin in order to work, I will try to make another request when create edit fails and will update it today

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

@mohammedhemaid thanks! What do you mean by restart the plugin?

@mohammedhemaid
Copy link
Contributor

yes, for now please, if you can restart the build or run the plugin again

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

@mohammedhemaid I did run the build again same error :(

@mohammedhemaid
Copy link
Contributor

@ccfiel it should work after few times, it's an issue in Amazon servers :(

@ccfiel
Copy link

ccfiel commented Sep 14, 2022

@mohammedhemaid ok, thanks! I have to go back to the old script that is working. I will post it here, maybe this can help.

  fastlane_require 'httparty'

  $amazon_developer_base_url = "https://developer.amazon.com/api/appstore"
  $amazon_auth_url = "https://api.amazon.com/auth/O2/token"
  $amazon_api_version = "v1"
  $amazon_app_id = "amzn1.devportal.mobileapp.xxxxxxxxxxx"
  $amazon_client_id = "amzn1.application-oa2-client.xxxxxx"
  $amazon_client_secret = "xxxxxxx"
  $release_notes = "new updates"

  desc "Deploy to the Amazon app store"
  lane :amazon_app_store do
    ##
    # Access Token
    ##
    puts "Get access token"
    response = HTTParty.post($amazon_auth_url, { headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }, body: { grant_type: "client_credentials", client_id: $amazon_client_id, client_secret: $amazon_client_secret, scope: "appstore::apps:readwrite" }})
    access_token = response["access_token"]

    ##
    # Create Edit
    ##
    UI.success "Get edit id"
    response = HTTParty.get("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => "application/json" }})
    UI.success response
    edit_status = response["status"]
    UI.success edit_status

    if edit_status == "IN_PROGRESS"
      UI.success "Using current release"
      edit_id = response["id"]
    elsif edit_status == "REVIEW"
      error(error_message:  "Amazon app store rejected the submission because an app is already under review for release.  Release to the Amazon store manually.")
      return
    else
      UI.success "Creating new release"
      edit_id = HTTParty.post("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => "application/json" }})["id"]
    end

    UI.success "Edit id: "+ edit_id

    ##
    # Get Current APK
    ##
    UI.success "Getting current APK information"
    response = HTTParty.get("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}/apks", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => "application/json" }})
    apk_id = response[0]["id"]
    UI.success "APK id: " + apk_id

    ##
    # Replace APK
    ##
    UI.success "Uploading APK"
    response = HTTParty.get("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}/apks/#{apk_id}", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => "application/json" }})
    etag = response.headers["ETag"]
    UI.success "ETag: " + etag
    response = HTTParty.put("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}/apks/#{apk_id}/replace", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => 'application/octet-stream', 'Accept' => 'application/json', 'If-Match' => etag}, body: File.new($path_to_apk, 'rb').read})
    UI.success "Response: " + response.to_s

    ##
    # Update Release Notes
    ##
    UI.success "Updating release notes"
    response = HTTParty.get("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}/listings", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => "application/json" }})
    etag = response.headers["ETag"]
    listing = response["listings"]["en-US"]
    listing["recentChanges"] = $release_notes
    UI.success listing.to_s
    HTTParty.put("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}/listings/en-US", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => 'application/json', 'If-Match' => etag}, body: listing.to_json})

    ##
    # Validate & Commit Edit
    ##
    etag = HTTParty.get("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}", { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => "application/json" }}).headers["ETag"]
    response = HTTParty.post("#{$amazon_developer_base_url}/#{$amazon_api_version}/applications/#{$amazon_app_id}/edits/#{edit_id}/commit", { headers: { 'Authorization' => "Bearer #{access_token}", 'If-Match' => etag }})

    if response.code != 200
      #Handle error with validation
      error(error_message: response.to_s)
    else
      #Successfully deployed
      UI.success "SUCCESS"
    end
  end

@redreceipt
Copy link

Any word on this? Judging from previous comments, Amazon servers were to blame? Has it gotten any better?

@ccfiel
Copy link

ccfiel commented Dec 23, 2022

@redreceipt I think its not because when I am using the script above do not have any problem.

@FlaShG
Copy link
Contributor

FlaShG commented Dec 24, 2022

We have not encountered this issue for a while now, without any modifications to the plugin. Seems to be solved for now.

@mohammedhemaid
Copy link
Contributor

The same to me, we were using the plugin for the last few months and we didn't add encounter any issue

@redreceipt
Copy link

Still fails for me, how can I debug?

Screenshot 2023-01-05 at 8 45 17 AM

@mohammedhemaid
Copy link
Contributor

@redreceipt Ok, I see I will investigate it and will try to fix it

@mohammedhemaid mohammedhemaid reopened this Jan 5, 2023
@redreceipt
Copy link

Let me know what info I can provide or how I can help. Not super familiar with Ruby so debug is difficult for me.

@mohammedhemaid
Copy link
Contributor

@redreceipt As I know, it's happening because of a server issue, I recheck that and I will put more explanation in the error logs

@redreceipt
Copy link

@redreceipt As I know, it's happening because of a server issue, I recheck that and I will put more explanation in the error logs

Did you ever put more information in the logs? I haven't seen a new release on the plug-in.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants