Chilkat Online Tools

UpdateApp Node.js Example

Amplify

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node17-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node17-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node17-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node17-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node17-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node17-macosx');
}

function chilkatExample() {

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var rest = new chilkat.Rest();
    var success;

    var authAws = new chilkat.AuthAws();
    authAws.AccessKey = "AWS_ACCESS_KEY";
    authAws.SecretKey = "AWS_SECRET_KEY";

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.Region = "us-west-2";
    authAws.ServiceName = "amplify";
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://amplify.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("amplify.us-west-2.amazonaws.com",443,true,true);
    if (success !== true) {
        console.log("ConnectFailReason: " + rest.ConnectFailReason);
        console.log(rest.LastErrorText);
        return;
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    var json = new chilkat.JsonObject();
    json.UpdateString("accessToken","string");
    json.UpdateString("autoBranchCreationConfig.basicAuthCredentials","string");
    json.UpdateString("autoBranchCreationConfig.buildSpec","string");
    json.UpdateInt("autoBranchCreationConfig.enableAutoBuild",123);
    json.UpdateInt("autoBranchCreationConfig.enableBasicAuth",123);
    json.UpdateInt("autoBranchCreationConfig.enablePerformanceMode",123);
    json.UpdateInt("autoBranchCreationConfig.enablePullRequestPreview",123);
    json.UpdateString("autoBranchCreationConfig.environmentVariables.string","string");
    json.UpdateString("autoBranchCreationConfig.framework","string");
    json.UpdateString("autoBranchCreationConfig.pullRequestEnvironmentName","string");
    json.UpdateString("autoBranchCreationConfig.stage","string");
    json.UpdateString("autoBranchCreationPatterns[0]","string");
    json.UpdateString("basicAuthCredentials","string");
    json.UpdateString("buildSpec","string");
    json.UpdateString("customHeaders","string");
    json.UpdateString("customRules[0].condition","string");
    json.UpdateString("customRules[0].source","string");
    json.UpdateString("customRules[0].status","string");
    json.UpdateString("customRules[0].target","string");
    json.UpdateString("description","string");
    json.UpdateInt("enableAutoBranchCreation",123);
    json.UpdateInt("enableBasicAuth",123);
    json.UpdateInt("enableBranchAutoBuild",123);
    json.UpdateInt("enableBranchAutoDeletion",123);
    json.UpdateString("environmentVariables.string","string");
    json.UpdateString("iamServiceRoleArn","string");
    json.UpdateString("name","string");
    json.UpdateString("oauthToken","string");
    json.UpdateString("platform","string");
    json.UpdateString("repository","string");

    // The JSON request body created by the above code:

    // {
    //   "accessToken": "string",
    //   "autoBranchCreationConfig": {
    //     "basicAuthCredentials": "string",
    //     "buildSpec": "string",
    //     "enableAutoBuild": boolean,
    //     "enableBasicAuth": boolean,
    //     "enablePerformanceMode": boolean,
    //     "enablePullRequestPreview": boolean,
    //     "environmentVariables": {
    //       "string": "string"
    //     },
    //     "framework": "string",
    //     "pullRequestEnvironmentName": "string",
    //     "stage": "string"
    //   },
    //   "autoBranchCreationPatterns": [
    //     "string"
    //   ],
    //   "basicAuthCredentials": "string",
    //   "buildSpec": "string",
    //   "customHeaders": "string",
    //   "customRules": [
    //     {
    //       "condition": "string",
    //       "source": "string",
    //       "status": "string",
    //       "target": "string"
    //     }
    //   ],
    //   "description": "string",
    //   "enableAutoBranchCreation": boolean,
    //   "enableBasicAuth": boolean,
    //   "enableBranchAutoBuild": boolean,
    //   "enableBranchAutoDeletion": boolean,
    //   "environmentVariables": {
    //     "string": "string"
    //   },
    //   "iamServiceRoleArn": "string",
    //   "name": "string",
    //   "oauthToken": "string",
    //   "platform": "string",
    //   "repository": "string"
    // }

    rest.AddHeader("Content-Type","application/x-amz-json-1.1");
    rest.AddHeader("X-Amz-Target","UpdateApp");

    var sbRequestBody = new chilkat.StringBuilder();
    json.EmitSb(sbRequestBody);
    var sbResponseBody = new chilkat.StringBuilder();
    success = rest.FullRequestSb("POST","/apps/{appId}",sbRequestBody,sbResponseBody);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    var respStatusCode = rest.ResponseStatusCode;
    console.log("response status code = " + respStatusCode);
    if (respStatusCode !== 200) {
        console.log("Response Header:");
        console.log(rest.ResponseHeader);
        console.log("Response Body:");
        console.log(sbResponseBody.GetAsString());
        return;
    }

    var jResp = new chilkat.JsonObject();
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var strVal;
    var condition;
    var source;
    var status;
    var target;

    var AppArn = jResp.StringOf("app.appArn");
    var AppId = jResp.StringOf("app.appId");
    var BasicAuthCredentials = jResp.StringOf("app.autoBranchCreationConfig.basicAuthCredentials");
    var BuildSpec = jResp.StringOf("app.autoBranchCreationConfig.buildSpec");
    var EnableAutoBuild = jResp.IntOf("app.autoBranchCreationConfig.enableAutoBuild");
    var EnableBasicAuth = jResp.IntOf("app.autoBranchCreationConfig.enableBasicAuth");
    var EnablePerformanceMode = jResp.IntOf("app.autoBranchCreationConfig.enablePerformanceMode");
    var EnablePullRequestPreview = jResp.IntOf("app.autoBranchCreationConfig.enablePullRequestPreview");
    var v_String = jResp.StringOf("app.autoBranchCreationConfig.environmentVariables.string");
    var Framework = jResp.StringOf("app.autoBranchCreationConfig.framework");
    var PullRequestEnvironmentName = jResp.StringOf("app.autoBranchCreationConfig.pullRequestEnvironmentName");
    var Stage = jResp.StringOf("app.autoBranchCreationConfig.stage");
    var appBasicAuthCredentials = jResp.StringOf("app.basicAuthCredentials");
    var appBuildSpec = jResp.StringOf("app.buildSpec");
    var CreateTime = jResp.IntOf("app.createTime");
    var CustomHeaders = jResp.StringOf("app.customHeaders");
    var DefaultDomain = jResp.StringOf("app.defaultDomain");
    var Description = jResp.StringOf("app.description");
    var EnableAutoBranchCreation = jResp.IntOf("app.enableAutoBranchCreation");
    var appEnableBasicAuth = jResp.IntOf("app.enableBasicAuth");
    var EnableBranchAutoBuild = jResp.IntOf("app.enableBranchAutoBuild");
    var EnableBranchAutoDeletion = jResp.IntOf("app.enableBranchAutoDeletion");
    var EnvironmentVariablesString = jResp.StringOf("app.environmentVariables.string");
    var IamServiceRoleArn = jResp.StringOf("app.iamServiceRoleArn");
    var Name = jResp.StringOf("app.name");
    var Platform = jResp.StringOf("app.platform");
    var BranchName = jResp.StringOf("app.productionBranch.branchName");
    var LastDeployTime = jResp.IntOf("app.productionBranch.lastDeployTime");
    var Status = jResp.StringOf("app.productionBranch.status");
    var ThumbnailUrl = jResp.StringOf("app.productionBranch.thumbnailUrl");
    var Repository = jResp.StringOf("app.repository");
    var RepositoryCloneMethod = jResp.StringOf("app.repositoryCloneMethod");
    var TagsString = jResp.StringOf("app.tags.string");
    var UpdateTime = jResp.IntOf("app.updateTime");
    var i = 0;
    var count_i = jResp.SizeOfArray("app.autoBranchCreationPatterns");
    while (i < count_i) {
        jResp.I = i;
        strVal = jResp.StringOf("app.autoBranchCreationPatterns[i]");
        i = i+1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("app.customRules");
    while (i < count_i) {
        jResp.I = i;
        condition = jResp.StringOf("app.customRules[i].condition");
        source = jResp.StringOf("app.customRules[i].source");
        status = jResp.StringOf("app.customRules[i].status");
        target = jResp.StringOf("app.customRules[i].target");
        i = i+1;
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "app": {
    //     "appArn": "string",
    //     "appId": "string",
    //     "autoBranchCreationConfig": {
    //       "basicAuthCredentials": "string",
    //       "buildSpec": "string",
    //       "enableAutoBuild": boolean,
    //       "enableBasicAuth": boolean,
    //       "enablePerformanceMode": boolean,
    //       "enablePullRequestPreview": boolean,
    //       "environmentVariables": {
    //         "string": "string"
    //       },
    //       "framework": "string",
    //       "pullRequestEnvironmentName": "string",
    //       "stage": "string"
    //     },
    //     "autoBranchCreationPatterns": [
    //       "string"
    //     ],
    //     "basicAuthCredentials": "string",
    //     "buildSpec": "string",
    //     "createTime": number,
    //     "customHeaders": "string",
    //     "customRules": [
    //       {
    //         "condition": "string",
    //         "source": "string",
    //         "status": "string",
    //         "target": "string"
    //       }
    //     ],
    //     "defaultDomain": "string",
    //     "description": "string",
    //     "enableAutoBranchCreation": boolean,
    //     "enableBasicAuth": boolean,
    //     "enableBranchAutoBuild": boolean,
    //     "enableBranchAutoDeletion": boolean,
    //     "environmentVariables": {
    //       "string": "string"
    //     },
    //     "iamServiceRoleArn": "string",
    //     "name": "string",
    //     "platform": "string",
    //     "productionBranch": {
    //       "branchName": "string",
    //       "lastDeployTime": number,
    //       "status": "string",
    //       "thumbnailUrl": "string"
    //     },
    //     "repository": "string",
    //     "repositoryCloneMethod": "string",
    //     "tags": {
    //       "string": "string"
    //     },
    //     "updateTime": number
    //   }
    // }

}

chilkatExample();