How to put an App Edit for Under review with NodeJS in Google Play using the androidpublisher v3

52 Views Asked by At

My goal is to fully automate the whole process of publish new updates for my apps, I have hundreds of apps and I've created the aab for each of them automatically, that's the context. Now I've created a NodeJS API to publish these aab and there is an endpoint to create an Edit using the androidpublisher as well. the code is this:

    const releaseNotes = [
     {
      language: 'pt-BR',
      text: note,
     },
    ];

    const auth = new google.auth.GoogleAuth({
      keyFile: `${serviceAccountPath}\\${projectName}.json`,
      scopes: ['https://www.googleapis.com/auth/androidpublisher'],
    });

    const androidPublisher = google.androidpublisher({
      version: 'v3',
      auth: auth,
    });

    // Step 1: Create a new edit
    const insertResp = await androidPublisher.edits.insert({
      packageName: pack,
    });

    const editId = insertResp.data.id;

    // Step 2: Upload the AAB
    const aabStream = createReadStream(aab);
    const uploadResponse = await androidPublisher.edits.bundles.upload({
      editId: editId,
      packageName: pack,
      media: {
        mimeType: 'application/octet-stream',
        body: aabStream,
      },
    });
    console.info('AAB upload response:', uploadResponse.data);

    // Step 3: Update the release track
    const trackUpdateResponse = await androidPublisher.edits.tracks.update({
      editId: editId,
      packageName: pack,
      track: trackMode,
      requestBody: {
        releases: [
          {
            status: 'completed',
            releaseNotes: releaseNotes,
          },
        ],
      },
    });
    console.info('Track update response:', trackUpdateResponse.data);

    // Step 4: Validate the Edit
    const validateResponse = await androidPublisher.edits.validate({
      packageName: pack,
      editId: editId,
    });
    console.info('Validation response:', validateResponse.data);


    // Step 5: Commit the changes: it only Add an app bundle into the library
    const commitResponse = await androidPublisher.edits.commit({
      packageName: pack,
      editId: editId,
      changesNotSentForReview: false,
    });
    console.info('Commit response:', commitResponse.data);

    // there is a Step 6?

So I want to know how can I put the bundle added to the library into the google revision, to it go live fully programatically. Am I missing some step? or some detail? or doing something wrong? this is inside a simple async function that receive these arguments. this code works but doesn't do the full process that I need it to do, as I mention the idea is to fully automate the process of publish an update for an app.

A plus question is should I use the callback way to handle this process instead of await/async? I mean instead of async/await could I use the then().catch() it's pretty ugly that's why I'm not using it here but if this solve the issue I'm glad to know why and how.

0

There are 0 best solutions below