Chilkat Online Tools

PureBasic / Anypoint Platform APIs / Create servergroup

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.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

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

    ; The following JSON is sent in the request body.

    ; {
    ;   "name": "test2",
    ;   "serverIds": [
    ;   ]
    ; }

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

    CkJsonObject::ckUpdateString(json,"name","test2")
    CkJsonObject::ckUpdateNewArray(json,"serverIds")

    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}}")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/hybrid/api/v1/serverGroups","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Authorization: Bearer {{token}}"
	-H "X-ANYPNT-ORG-ID: {{organization_id}}"
	-H "X-ANYPNT-ENV-ID: {{environment_id}}"
	-d '{
   "name":"test2",
   "serverIds":[
      
   ]
}'
https://domain.com/hybrid/api/v1/serverGroups

Postman Collection Item JSON

{
  "name": "Create servergroup",
  "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   \"name\":\"test2\",\r\n   \"serverIds\":[\r\n      \r\n   ]\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{url}}/hybrid/api/v1/serverGroups",
      "host": [
        "{{url}}"
      ],
      "path": [
        "hybrid",
        "api",
        "v1",
        "serverGroups"
      ]
    }
  },
  "response": [
  ]
}