PhoneGap Build API and RestSharp

PhoneGap Build API and RestSharp

July 23, 2018 Development Mobile Uncategorized 0

For many people using phonegap build aside from using their terminal, pgb-cli, or node.js options you may want to write code without using a curl request. I ran into this issue when building an application that directly communicates with the phonegap build api. I struggled to find a solution when uploading a zip file and posting it for a NEW build. Unfortunately their support is nothing short of useless when it comes to these things.

Here’s what I did to make it work.

var client = new RestClient(string.Format("{1}apps?auth_token={0}"),token, url));

RestRequest request = new RestRequest(string.Format("{1}apps?auth_token={0}", token, url), Method.POST);

request.AddFileBytes("file", File.ReadAllBytes(file), Path.GetFileName(file), "application/octet-stream");

request.AddParameter("multipart/form-data", new {data = dataString}, "multipart/form-data", ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

return response.Content;

I had one issue which was easily resolved after uploading it to phonegap. Selecting the proper keys to build with. In this case I used the terminal option they offer to set my default keys with the following command. (I did not have the radio buttons in the keys section of phonegap build to select a default)

pgb update-key {keyid} {default}

Once I validated that the keys were in fact set to defaults I updated my json to post as follows.

string data = serializer.Serialize(
new { title = model.title,
      create_method = "file",  
      @default= true, 
      keys = new {
                   ios = new {
                               id = , 
                               password = ios.password 
                   android = new { 
                               id = , 
                               key_pw = android.key_pw, 
                               keystore_pw = android.keystore_pw

In doing this I was able make a call to unlock the keys prior to uploading a build and successfully generate a new app in phonegap build.