Chilkat Online Tools

C++ / Core Services API / GetInstance

Back to Collection Items

#include <CkHttp.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http;
    bool success;

    http.SetRequestHeader("Authorization","{{signature}}");
    http.SetRequestHeader("Date","{{date}}");

    CkStringBuilder sbResponseBody;
    success = http.QuickGetSb("https://iaas.{{region}}.oraclecloud.com/20160918/instances/:instanceId",sbResponseBody);
    if (success == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = http.get_LastStatus();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << http.lastHeader() << "\r\n";
        std::cout << "Failed." << "\r\n";
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "id": "sit dolor",
    //   "compartmentId": "et esse",
    //   "shape": "sunt veniam",
    //   "region": "laboris",
    //   "availabilityDomain": "dolor",
    //   "lifecycleState": "TERMINATED",
    //   "timeCreated": "2006-02-03T20:50:31.716Z",
    //   "agentConfig": {
    //     "areAllPluginsDisabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isManagementDisabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isMonitoringDisabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "pluginsConfig": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "availabilityConfig": {
    //     "isLiveMigrationPreferred": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "recoveryAction": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "capacityReservationId": "occaecat sint id",
    //   "dedicatedVmHostId": "ipsum dolor incididunt sit ex",
    //   "definedTags": {},
    //   "displayName": "consequat aliquip magna ullamco",
    //   "extendedMetadata": {},
    //   "faultDomain": "incididunt esse",
    //   "freeformTags": {},
    //   "imageId": "dolor nulla consequat ipsum",
    //   "instanceOptions": {
    //     "areLegacyImdsEndpointsDisabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "ipxeScript": "anim magna",
    //   "launchMode": "CUSTOM",
    //   "launchOptions": {
    //     "bootVolumeType": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "firmware": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isConsistentVolumeNamingEnabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isPvEncryptionInTransitEnabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "networkType": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "remoteDataVolumeType": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "metadata": {},
    //   "platformConfig": {
    //     "type": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isMeasuredBootEnabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isSecureBootEnabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "isTrustedPlatformModuleEnabled": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "preemptibleInstanceConfig": {
    //     "preemptionAction": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "shapeConfig": {
    //     "baselineOcpuUtilization": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "gpuDescription": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "gpus": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "localDiskDescription": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "localDisks": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "localDisksTotalSizeInGBs": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "maxVnicAttachments": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "memoryInGBs": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "networkingBandwidthInGbps": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "ocpus": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     },
    //     "processorDescription": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "sourceDetails": {
    //     "sourceType": {
    //       "value": "<Error: Too many levels of nesting to fake this schema>"
    //     }
    //   },
    //   "timeMaintenanceRebootDue": "1973-07-06T14:36:00.263Z"
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const char *id = jResp.stringOf("id");
    const char *compartmentId = jResp.stringOf("compartmentId");
    const char *shape = jResp.stringOf("shape");
    const char *region = jResp.stringOf("region");
    const char *availabilityDomain = jResp.stringOf("availabilityDomain");
    const char *lifecycleState = jResp.stringOf("lifecycleState");
    const char *timeCreated = jResp.stringOf("timeCreated");
    const char *Value = jResp.stringOf("agentConfig.areAllPluginsDisabled.value");
    const char *IsManagementDisabledValue = jResp.stringOf("agentConfig.isManagementDisabled.value");
    const char *IsMonitoringDisabledValue = jResp.stringOf("agentConfig.isMonitoringDisabled.value");
    const char *PluginsConfigValue = jResp.stringOf("agentConfig.pluginsConfig.value");
    const char *IsLiveMigrationPreferredValue = jResp.stringOf("availabilityConfig.isLiveMigrationPreferred.value");
    const char *RecoveryActionValue = jResp.stringOf("availabilityConfig.recoveryAction.value");
    const char *capacityReservationId = jResp.stringOf("capacityReservationId");
    const char *dedicatedVmHostId = jResp.stringOf("dedicatedVmHostId");
    const char *displayName = jResp.stringOf("displayName");
    const char *faultDomain = jResp.stringOf("faultDomain");
    const char *imageId = jResp.stringOf("imageId");
    const char *AreLegacyImdsEndpointsDisabledValue = jResp.stringOf("instanceOptions.areLegacyImdsEndpointsDisabled.value");
    const char *ipxeScript = jResp.stringOf("ipxeScript");
    const char *launchMode = jResp.stringOf("launchMode");
    const char *BootVolumeTypeValue = jResp.stringOf("launchOptions.bootVolumeType.value");
    const char *FirmwareValue = jResp.stringOf("launchOptions.firmware.value");
    const char *IsConsistentVolumeNamingEnabledValue = jResp.stringOf("launchOptions.isConsistentVolumeNamingEnabled.value");
    const char *IsPvEncryptionInTransitEnabledValue = jResp.stringOf("launchOptions.isPvEncryptionInTransitEnabled.value");
    const char *NetworkTypeValue = jResp.stringOf("launchOptions.networkType.value");
    const char *RemoteDataVolumeTypeValue = jResp.stringOf("launchOptions.remoteDataVolumeType.value");
    const char *TypeValue = jResp.stringOf("platformConfig.type.value");
    const char *IsMeasuredBootEnabledValue = jResp.stringOf("platformConfig.isMeasuredBootEnabled.value");
    const char *IsSecureBootEnabledValue = jResp.stringOf("platformConfig.isSecureBootEnabled.value");
    const char *IsTrustedPlatformModuleEnabledValue = jResp.stringOf("platformConfig.isTrustedPlatformModuleEnabled.value");
    const char *PreemptionActionValue = jResp.stringOf("preemptibleInstanceConfig.preemptionAction.value");
    const char *BaselineOcpuUtilizationValue = jResp.stringOf("shapeConfig.baselineOcpuUtilization.value");
    const char *GpuDescriptionValue = jResp.stringOf("shapeConfig.gpuDescription.value");
    const char *GpusValue = jResp.stringOf("shapeConfig.gpus.value");
    const char *LocalDiskDescriptionValue = jResp.stringOf("shapeConfig.localDiskDescription.value");
    const char *LocalDisksValue = jResp.stringOf("shapeConfig.localDisks.value");
    const char *LocalDisksTotalSizeInGBsValue = jResp.stringOf("shapeConfig.localDisksTotalSizeInGBs.value");
    const char *MaxVnicAttachmentsValue = jResp.stringOf("shapeConfig.maxVnicAttachments.value");
    const char *MemoryInGBsValue = jResp.stringOf("shapeConfig.memoryInGBs.value");
    const char *NetworkingBandwidthInGbpsValue = jResp.stringOf("shapeConfig.networkingBandwidthInGbps.value");
    const char *OcpusValue = jResp.stringOf("shapeConfig.ocpus.value");
    const char *ProcessorDescriptionValue = jResp.stringOf("shapeConfig.processorDescription.value");
    const char *SourceTypeValue = jResp.stringOf("sourceDetails.sourceType.value");
    const char *timeMaintenanceRebootDue = jResp.stringOf("timeMaintenanceRebootDue");
    }

Curl Command

curl -X GET
	-H "Date: {{date}}"
	-H "Authorization: {{signature}}"
https://iaas.{{region}}.oraclecloud.com/20160918/instances/:instanceId

Postman Collection Item JSON

{
  "name": "GetInstance",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Date",
        "value": "{{date}}",
        "description": "(Required) Current Date",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "{{signature}}",
        "description": "(Required) Signature Authentication on Authorization header",
        "type": "text"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/instances/:instanceId",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "instances",
        ":instanceId"
      ],
      "variable": [
        {
          "key": "instanceId",
          "value": "officia sed",
          "description": "(Required) The [OCID](/iaas/Content/General/Concepts/identifiers.htm) of the instance."
        }
      ]
    },
    "description": "Gets information about the specified instance."
  },
  "response": [
    {
      "name": "The instance was retrieved.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/instances/:instanceId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "instances",
            ":instanceId"
          ],
          "variable": [
            {
              "key": "instanceId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "etag",
          "value": "officia sed",
          "description": "For optimistic concurrency control. See `if-match`.\n"
        },
        {
          "key": "opc-request-id",
          "value": "officia sed",
          "description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"id\": \"sit dolor\",\n \"compartmentId\": \"et esse\",\n \"shape\": \"sunt veniam\",\n \"region\": \"laboris\",\n \"availabilityDomain\": \"dolor\",\n \"lifecycleState\": \"TERMINATED\",\n \"timeCreated\": \"2006-02-03T20:50:31.716Z\",\n \"agentConfig\": {\n  \"areAllPluginsDisabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isManagementDisabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isMonitoringDisabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"pluginsConfig\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"availabilityConfig\": {\n  \"isLiveMigrationPreferred\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"recoveryAction\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"capacityReservationId\": \"occaecat sint id\",\n \"dedicatedVmHostId\": \"ipsum dolor incididunt sit ex\",\n \"definedTags\": {},\n \"displayName\": \"consequat aliquip magna ullamco\",\n \"extendedMetadata\": {},\n \"faultDomain\": \"incididunt esse\",\n \"freeformTags\": {},\n \"imageId\": \"dolor nulla consequat ipsum\",\n \"instanceOptions\": {\n  \"areLegacyImdsEndpointsDisabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"ipxeScript\": \"anim magna\",\n \"launchMode\": \"CUSTOM\",\n \"launchOptions\": {\n  \"bootVolumeType\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"firmware\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isConsistentVolumeNamingEnabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isPvEncryptionInTransitEnabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"networkType\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"remoteDataVolumeType\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"metadata\": {},\n \"platformConfig\": {\n  \"type\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isMeasuredBootEnabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isSecureBootEnabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"isTrustedPlatformModuleEnabled\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"preemptibleInstanceConfig\": {\n  \"preemptionAction\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"shapeConfig\": {\n  \"baselineOcpuUtilization\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"gpuDescription\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"gpus\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"localDiskDescription\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"localDisks\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"localDisksTotalSizeInGBs\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"maxVnicAttachments\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"memoryInGBs\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"networkingBandwidthInGbps\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"ocpus\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  },\n  \"processorDescription\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"sourceDetails\": {\n  \"sourceType\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n },\n \"timeMaintenanceRebootDue\": \"1973-07-06T14:36:00.263Z\"\n}"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/instances/:instanceId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "instances",
            ":instanceId"
          ],
          "variable": [
            {
              "key": "instanceId"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "opc-request-id",
          "value": "officia sed",
          "description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"code\": \"et exercitation Excepteur\",\n \"message\": \"irure sit\"\n}"
    },
    {
      "name": "Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/instances/:instanceId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "instances",
            ":instanceId"
          ],
          "variable": [
            {
              "key": "instanceId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "opc-request-id",
          "value": "officia sed",
          "description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"code\": \"et exercitation Excepteur\",\n \"message\": \"irure sit\"\n}"
    },
    {
      "name": "Internal Server Error",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/instances/:instanceId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "instances",
            ":instanceId"
          ],
          "variable": [
            {
              "key": "instanceId"
            }
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "opc-request-id",
          "value": "officia sed",
          "description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"code\": \"et exercitation Excepteur\",\n \"message\": \"irure sit\"\n}"
    },
    {
      "name": "An error has occurred.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/instances/:instanceId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "instances",
            ":instanceId"
          ],
          "variable": [
            {
              "key": "instanceId"
            }
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "opc-request-id",
          "value": "officia sed",
          "description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"code\": \"et exercitation Excepteur\",\n \"message\": \"irure sit\"\n}"
    }
  ]
}