Chilkat Online Tools

SQL Server / Anypoint Platform APIs / Deploy application

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

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

    -- The following JSON is sent in the request body.

    -- {
    --   "applicationInfo": {
    --     "fileName": "HTTP Request Response with Logger",
    --     "muleVersion": {
    --       "version": "4.3.0",
    --       "updateId": "606cc71944b5ff1b07f791e3"
    --     },
    --     "properties": {
    --       "anypoint.platform.config.analytics.agent.enabled": "false"
    --     },
    --     "logLevels": [
    --     ],
    --     "trackingSettings": {
    --       "trackingLevel": "DISABLED"
    --     },
    --     "deploymentGroup": null,
    --     "monitoringEnabled": true,
    --     "monitoringAutoRestart": true,
    --     "persistentQueues": false,
    --     "persistentQueuesEncrypted": false,
    --     "workers": {
    --       "amount": 1,
    --       "type": {
    --         "name": "Micro",
    --         "weight": 0.1,
    --         "cpu": "0.1 vCores",
    --         "memory": "500 MB memory"
    --       }
    --     },
    --     "objectStoreV1": false,
    --     "loggingNgEnabled": true,
    --     "loggingCustomLog4JEnabled": false,
    --     "staticIPsEnabled": false,
    --     "domain": "postman-api"
    --   },
    --   "applicationSource": {
    --     "source": "EXCHANGE",
    --     "groupId": "org.mule.examples",
    --     "artifactId": "http-request-response-with-logger",
    --     "version": "2.1.4",
    --     "organizationId": "68ef9520-24e9-4cf2-b2f5-620025690913"
    --   },
    --   "autoStart": true
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.fileName', 'HTTP Request Response with Logger'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.muleVersion.version', '4.3.0'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.muleVersion.updateId', '606cc71944b5ff1b07f791e3'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.properties."anypoint.platform.config.analytics.agent.enabled"', 'false'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'applicationInfo.logLevels'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.trackingSettings.trackingLevel', 'DISABLED'
    EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'applicationInfo.deploymentGroup'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.monitoringEnabled', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.monitoringAutoRestart', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.persistentQueues', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.persistentQueuesEncrypted', 0
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'applicationInfo.workers.amount', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.workers.type.name', 'Micro'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'applicationInfo.workers.type.weight', '0.1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.workers.type.cpu', '0.1 vCores'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.workers.type.memory', '500 MB memory'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.objectStoreV1', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.loggingNgEnabled', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.loggingCustomLog4JEnabled', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'applicationInfo.staticIPsEnabled', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationInfo.domain', 'postman-api'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationSource.source', 'EXCHANGE'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationSource.groupId', 'org.mule.examples'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationSource.artifactId', 'http-request-response-with-logger'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationSource.version', '2.1.4'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationSource.organizationId', '68ef9520-24e9-4cf2-b2f5-620025690913'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'autoStart', 1

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-ANYPNT-ENV-ID', '{{environment_id}}'
    -- Adds the "Authorization: Bearer {{token}}" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '{{token}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-ANYPNT-ORG-ID', '{{organization_id}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/cloudhub/api/v2/applications', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer {{token}}"
	-H "X-ANYPNT-ORG-ID: {{organization_id}}"
	-H "X-ANYPNT-ENV-ID: {{environment_id}}"
	-d '{
   "applicationInfo":{
      "fileName":"HTTP Request Response with Logger",
      "muleVersion":{
         "version":"4.3.0",
         "updateId":"606cc71944b5ff1b07f791e3"
      },
      "properties":{
         "anypoint.platform.config.analytics.agent.enabled":"false"
      },
      "logLevels":[
         
      ],
      "trackingSettings":{
         "trackingLevel":"DISABLED"
      },
      "deploymentGroup":null,
      "monitoringEnabled":true,
      "monitoringAutoRestart":true,
      "persistentQueues":false,
      "persistentQueuesEncrypted":false,
      "workers":{
         "amount":1,
         "type":{
            "name":"Micro",
            "weight":0.1,
            "cpu":"0.1 vCores",
            "memory":"500 MB memory"
         }
      },
      "objectStoreV1":false,
      "loggingNgEnabled":true,
      "loggingCustomLog4JEnabled":false,
      "staticIPsEnabled":false,
      "domain":"postman-api"
   },
   "applicationSource":{
      "source":"EXCHANGE",
      "groupId":"org.mule.examples",
      "artifactId":"http-request-response-with-logger",
      "version":"2.1.4",
      "organizationId":"68ef9520-24e9-4cf2-b2f5-620025690913"
   },
   "autoStart":true
}'
https://domain.com/cloudhub/api/v2/applications

Postman Collection Item JSON

{
  "name": "Deploy application",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{token}}",
        "type": "text"
      },
      {
        "key": "X-ANYPNT-ORG-ID",
        "value": "{{organization_id}}",
        "type": "text"
      },
      {
        "key": "X-ANYPNT-ENV-ID",
        "value": "{{environment_id}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n   \"applicationInfo\":{\r\n      \"fileName\":\"HTTP Request Response with Logger\",\r\n      \"muleVersion\":{\r\n         \"version\":\"4.3.0\",\r\n         \"updateId\":\"606cc71944b5ff1b07f791e3\"\r\n      },\r\n      \"properties\":{\r\n         \"anypoint.platform.config.analytics.agent.enabled\":\"false\"\r\n      },\r\n      \"logLevels\":[\r\n         \r\n      ],\r\n      \"trackingSettings\":{\r\n         \"trackingLevel\":\"DISABLED\"\r\n      },\r\n      \"deploymentGroup\":null,\r\n      \"monitoringEnabled\":true,\r\n      \"monitoringAutoRestart\":true,\r\n      \"persistentQueues\":false,\r\n      \"persistentQueuesEncrypted\":false,\r\n      \"workers\":{\r\n         \"amount\":1,\r\n         \"type\":{\r\n            \"name\":\"Micro\",\r\n            \"weight\":0.1,\r\n            \"cpu\":\"0.1 vCores\",\r\n            \"memory\":\"500 MB memory\"\r\n         }\r\n      },\r\n      \"objectStoreV1\":false,\r\n      \"loggingNgEnabled\":true,\r\n      \"loggingCustomLog4JEnabled\":false,\r\n      \"staticIPsEnabled\":false,\r\n      \"domain\":\"postman-api\"\r\n   },\r\n   \"applicationSource\":{\r\n      \"source\":\"EXCHANGE\",\r\n      \"groupId\":\"org.mule.examples\",\r\n      \"artifactId\":\"http-request-response-with-logger\",\r\n      \"version\":\"2.1.4\",\r\n      \"organizationId\":\"68ef9520-24e9-4cf2-b2f5-620025690913\"\r\n   },\r\n   \"autoStart\":true\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{url}}/cloudhub/api/v2/applications",
      "host": [
        "{{url}}"
      ],
      "path": [
        "cloudhub",
        "api",
        "v2",
        "applications"
      ]
    }
  },
  "response": [
  ]
}