Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Track names in request path and request body must match. #59

Open
MarcoAltranDC opened this issue Mar 13, 2020 · 1 comment
Open

Track names in request path and request body must match. #59

MarcoAltranDC opened this issue Mar 13, 2020 · 1 comment

Comments

@MarcoAltranDC
Copy link

From the last 24 hours I've been getting this error. The code was working fine before:

Mar 13, 2020 10:48:54 AM BasicUploadApk main

  | INFO: Created edit with id: 11886469901726234722
  | Mar 13, 2020 10:49:09 AM BasicUploadApk main
  | INFO: Version code 11180 has been uploaded
  | Mar 13, 2020 10:49:09 AM BasicUploadApk main
  | INFO: Version code 12180 has been uploaded
  | Mar 13, 2020 10:49:10 AM BasicUploadApk main
  | SEVERE: BasicUploadApk: Exception was thrown while uploading apk to internal track (for apkFilePath=../wallet/build/app/outputs/apk/qa/release/app-qa-armeabi-v7a-release.apk)
  | com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
  | {
  | "code" : 400,
  | "errors" : [ {
  | "domain" : "global",
  | "message" : "Track names in request path and request body must match.",
  | "reason" : "badRequest"
  | } ],
  | "message" : "Track names in request path and request body must match.",
  | "status" : "INVALID_ARGUMENT"
  | }
  | at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
  | at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
  | at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
  | at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1092)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
  | at BasicUploadApk.main(BasicUploadApk.java:100)
  |  
  | Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
  | {
  | "code" : 400,
  | "errors" : [ {
  | "domain" : "global",
  | "message" : "Track names in request path and request body must match.",
  | "reason" : "badRequest"
  | } ],
  | "message" : "Track names in request path and request body must match.",
  | "status" : "INVALID_ARGUMENT"
  | }
  | at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
  | at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
  | at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
  | at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1092)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
  | at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
  | at BasicUploadApk.main(BasicUploadApk.java:100)

Here is my main method:

public static void main(String[] args) throws IOException, GeneralSecurityException {
        String applicationName = args[0];
        String packageName = args[1];
        String serviceAccountEmail = args[2];
        String apkFilePath32 = args[3];
        String apkFilePath64 = args[4];
        try {

            Preconditions.checkArgument(!Strings.isNullOrEmpty(packageName),
                    "ApplicationConfig.PACKAGE_NAME cannot be null or empty!");

            // Create the API service.
            AndroidPublisher service = AndroidPublisherHelper.init(
                    applicationName, serviceAccountEmail);
            final Edits edits = service.edits();

            // Create a new edit to make changes to your listing.
            Insert editRequest = edits
                    .insert(packageName,
                            null /** no content */);
            AppEdit edit = editRequest.execute();
            final String editId = edit.getId();
            log.info(String.format("Created edit with id: %s", editId));

            // Upload new apk to developer console

            final AbstractInputStreamContent apkFile32 =
                    new FileContent(AndroidPublisherHelper.MIME_TYPE_APK, new File(apkFilePath32));
            final AbstractInputStreamContent apkFile64 =
                    new FileContent(AndroidPublisherHelper.MIME_TYPE_APK, new File(apkFilePath64));
            Upload uploadRequest32 = edits
                    .apks()
                    .upload(packageName,
                            editId,
                            apkFile32);
            Upload uploadRequest64 = edits
                    .apks()
                    .upload(packageName,
                            editId,
                            apkFile64);
            Apk apk32 = uploadRequest32.execute();
            Apk apk64 = uploadRequest64.execute();
            log.info(String.format("Version code %d has been uploaded",
                    apk32.getVersionCode()));
            log.info(String.format("Version code %d has been uploaded",
                    apk64.getVersionCode()));

            // Assign apk to alpha track.
            List<Long> apkVersionCodes = new ArrayList<>();
            apkVersionCodes.add(Long.valueOf(apk32.getVersionCode()));
            apkVersionCodes.add(Long.valueOf(apk64.getVersionCode()));
            Update updateTrackRequest = edits
                    .tracks()
                    .update(packageName,
                            editId,
                            TRACK_INTERNAL,
                            new Track().setReleases(
                                    Collections.singletonList(
                                            new TrackRelease()
                                                    .setVersionCodes(apkVersionCodes)
                                                    .setStatus("completed")
                                                    .setReleaseNotes(Collections.singletonList(
                                                            new LocalizedText()
                                                                    .setLanguage("en-US")
                                                                    .setText("Automated apk deploy"))))));
            Track updatedTrack = updateTrackRequest.execute();
            log.info(String.format("Track %s has been updated.", updatedTrack.getTrack()));

            // Commit changes for edit.
            Commit commitRequest = edits.commit(packageName, editId);
            AppEdit appEdit = commitRequest.execute();
            log.info(String.format("App edit with id %s has been committed", appEdit.getId()));

        } catch (IOException | GeneralSecurityException ex) {
            log.error("BasicUploadApk: Exception was thrown while uploading apk to internal track (for apkFilePath=" + apkFilePath32 + ")", ex);
            throw ex;
        }
    }
@nkeerthy-okta
Copy link

Now the body to have track as param
We need to Update the code for updateTrackRequest
For you this change should work
.setText(ALPHA_RELEASE_NOTES)))))).setTrack(TRACK_INTERNAL);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants