Chilkat Online Tools

PureBasic / Anypoint Platform APIs / /organizations

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::ckSetRequestHeader(http,"X-ANYPNT-ENV-ID","{{environment_id}}")
    ; Adds the "Authorization: Bearer {{token}}" header.
    CkHttp::setCkAuthToken(http, "{{token}}")
    CkHttp::ckSetRequestHeader(http,"X-ANYPNT-ORG-ID","{{organization_id}}")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://monitoring.anypoint.mulesoft.com/monitoring/archive/api/v1/organizations",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

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

    ; {
    ;   "resources": [
    ;     {
    ;       "id": "in incididu"
    ;     },
    ;     {
    ;       "id": "cillum culpa"
    ;     }
    ;   ]
    ; }

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

    id.s

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"resources")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckStringOf(jResp,"resources[i].id")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-H "Authorization: Bearer {{token}}"
	-H "X-ANYPNT-ORG-ID: {{organization_id}}"
	-H "X-ANYPNT-ENV-ID: {{environment_id}}"
https://monitoring.anypoint.mulesoft.com/monitoring/archive/api/v1/organizations

Postman Collection Item JSON

{
  "name": "/organizations",
  "request": {
    "method": "GET",
    "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"
      }
    ],
    "url": {
      "raw": "https://monitoring.anypoint.mulesoft.com/monitoring/archive/api/v1/organizations",
      "protocol": "https",
      "host": [
        "monitoring",
        "anypoint",
        "mulesoft",
        "com"
      ],
      "path": [
        "monitoring",
        "archive",
        "api",
        "v1",
        "organizations"
      ]
    },
    "description": "Returns a list of organization identifiers for the organizations that have archived data.  If this path contains no\ndata, then an empty list is returned.\n"
  },
  "response": [
    {
      "name": "Untitled Example",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/organizations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "organizations"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"resources\": [\n  {\n   \"id\": \"in incididu\"\n  },\n  {\n   \"id\": \"cillum culpa\"\n  }\n ]\n}"
    },
    {
      "name": "The client is sending more than the allowed number of requests per unit time",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/organizations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "organizations"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "The API service is temporarily unreachable.  Please try again later.  Contact support if problem persists.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/organizations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "organizations"
          ]
        }
      },
      "status": "Gateway Timeout",
      "code": 504,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}