3 Replies Latest reply on Apr 28, 2017 7:53 AM by danielem18727002

    PhoneGap Build API - Set the keys for iOS and Android

    danielem18727002

      Hi,

       

      I am using the API for NodeJS and once I have successfully authenticate I am trying to unlock/set the keys for iOS or Android according if it is a develop or a release build - I still didn't managed to set the key through the API but only by the website.

       

      This is the documentation I am using PhoneGap Build API for Node.js  and this is the code I've got in place:

       

      var pgBuild = require('phonegap-build-api');
      pgBuild.auth({ token: phonegapBuildToken }, authenticationResponse);
      
      function authenticationResponse(e, api){
        if(e !== null){
          console.log('There have been an error during the authentication process. \n' + e);
          return;
        }
      
      
        unlockAndroidKeyMethod(api);
        unlockiOSKeyMethod(api);
      
      
        var options = {
            form: {
              data: {
                debug: false,
                platforms: ['android', 'ios'],
                create_method: 'file'
            },
              file: './ppmobilev3.zip'
            }
          };
      
      
        api.put(phonegapEndpoint, options, function(ee, data) {
          if(data !== null && !ee){
            console.log('BUILD IN PROGRESS...');
            ...
          }
          else {
            console.log('There have been an error on the build process. \n' + ee);
          }
        });
      }
      
      
      
      
      
      
      
      
      

       

      I have this 2 functions which I would like to use to set the keys:

       

      function unlockAndroidKeyMethod(api){
        var unlockAndroidKeyForm = {
          form: {
            data: {
              key_pw: 'passwd1234',
              keystore_pw: 'passwd1234'
            }
          }
        };
        api.put('/keys/android/227397', unlockAndroidKeyForm, function (e, data){
          console.log(e);
          console.log(data);
        });
      }
      
      
      function unlockiOSKeyMethod(api){
        var unlockiOSKeyForm = {
          form: {
            data: {
              password: 'passwd1234'
            }
          }
        };
        var iOSkeyID = (buildForProduction) ? '648386' : '648379';
      
      
        api.put('/keys/ios/' + iOSkeyID, unlockiOSKeyForm, function (e, data){
          console.log(e);
          console.log(data);
        });
      }
      
      
      
      
      
      

       

      This is what I get back as 'data' from api.put call in the above 2 functions:

      { id: 227397,
        title: 'peopleplanner',
        platform: 'android',
        created_at: '2017-01-26 09:55:13 -0800',
        last_used: '2017-04-07 07:11:36 -0700',
        link: '/api/v1/keys/android/227397',
        default: false,
        alias: 'peopleplanner',
        locked: false 
      }
      
      
      { id: 648379,
        title: 'My iOS Develop Signing Key',
        platform: 'ios',
        created_at: '2017-01-26 09:14:21 -0800',
        last_used: '2017-04-27 09:48:21 -0700',
        link: '/api/v1/keys/ios/648379',
        default: false,
        cert_name: 'Certificates.p12',
        provision: 'PPMobileV3__Jan_2017.mobileprovision',
        locked: false,
        role: 'developer' 
      }
      
      
      
      

       

      It might unlock the keys but it is not setting what key I want to use. How do you do that?

       

      I would like to implement something like:

      if is debug mode: Set Android key to null and iOS key to use the develop provisioning profile

      if is production mode: Set Android key to the proper key and iOS key to use the production provisioning profile...is this possible?

       

      Thanks

        • 1. Re: PhoneGap Build API - Set the keys for iOS and Android
          ryanskihead Adobe Employee

          You're unlocking your keys but you're not updating your app with the key you'd like to sign with. Here's an example with curl:

           

          curl -d 'data={"keys": { "android":{ "id":67890, "key_pw":"mypass", "keystore_pw":"mypass" } } }' -X PUT https://build.phonegap.com/api/v1/apps/12345?auth_token=$PGB_AUTH_TOKEN

           

          that call tells the service to set app 12345 to use key 67890, and unlocks that key as well with those passwords.

           

          A quick conversion to node might be something like this:

           

          1. var unlockAndroidKeyForm = { 
          2.     form: { 
          3.       data: {
          4.         keys: {
          5.           android: {
          6.             id: 227397,
          7.             key_pw: 'passwd1234'
          8.             keystore_pw: 'passwd1234' 
          9.      
          10.           } 
          11.       }
          12.     } 
          13.   }; 
          14.   api.put('/apps/12345', unlockAndroidKeyForm, function (e, data){ 
          15.     console.log(e); 
          16.     console.log(data); 
          17.   });
          • 2. Re: PhoneGap Build API - Set the keys for iOS and Android
            danielem18727002 Level 1

            Hi,

             

            thanks a lot - that is great! I did managed to set the keys now but I do have another issue related to it, I know don't know how to not select any key!

             

            I'll show you what I mean - this is the new code I have in place:

             

            var iOSkeyID = (buildForProduction) ? '648386' : '648379';

            var options = {

              form: {

               data: {

               keys: {

               ios: {

               id: iOSkeyID,
               password: 'passwd1234'
               }

              },
               debug: false,
               platforms: ['android', 'ios'],
               create_method: 'file'
              },
               file: './ppmobilev3.zip'
              }

            };

            if (buildForProduction){

              options.form.data.keys.android = {

               id: '227397',
               key_pw: 'passwd1234',
               keystore_pw: 'passwd1234'
              }

            }

             

            it is working properly for the iOS since I can switch between the 2 keys but for the Android where I need to either set the key or use 'no key' it's not working as it is always using the existing key.

             

            If buildForProduction is true I set the key for android:

            options.form.data.keys.android = {

               id: '227397',
               key_pw: 'passwd1234',
               keystore_pw: 'passwd1234'
              }

             

            now if the production is false I don't set the key but PhoneGap use whatever key is set on the web site:

            Screenshot_4.png

             

            So the question is, how do I set the options 'No key selected' for the android?

             

            I have tried to pass an id of null or 'no_key' or just don't pass anything but it still using the current selected key from the website.

             

            Thanks

            • 3. Re: PhoneGap Build API - Set the keys for iOS and Android
              danielem18727002 Level 1

              Never mind about the above question - I don't really need to switch the Key of the Android to 'none'.

               

              I needed for the iOS since you cannot load an app with a production key for testing but you can do it with the Android

               

              Thanks a lot ryanskihead