Chilkat Online Tools

unicodeC / Squadcast API V3 / Update Squad

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

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

    // {
    //   "members": [
    //     "5df9d90aba2cb0c5a4f12d44",
    //     "5df9d90aba2cb0c5a4f12d45",
    //     "5df9d90aba2cb0c5a4f12d46"
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"members[0]",L"5df9d90aba2cb0c5a4f12d44");
    CkJsonObjectW_UpdateString(json,L"members[1]",L"5df9d90aba2cb0c5a4f12d45");
    CkJsonObjectW_UpdateString(json,L"members[2]",L"5df9d90aba2cb0c5a4f12d46");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://api.squadcast.com/v3/squads/:squadID",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
	"members":[
        "5df9d90aba2cb0c5a4f12d44",
        "5df9d90aba2cb0c5a4f12d45",
        "5df9d90aba2cb0c5a4f12d46"
    ]
}'
https://api.squadcast.com/v3/squads/:squadID

Postman Collection Item JSON

{
  "name": "Update Squad",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{sq_pb_auth_header}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/squads/:squadID",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "squads",
        ":squadID"
      ],
      "variable": [
        {
          "key": "squadID",
          "value": "5ed4e5977cc8a1daa90d56eb",
          "type": "string"
        }
      ]
    },
    "description": "This endpoint is used to update the squads details.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `squad-update` scope."
  },
  "response": [
    {
      "name": "200 OK",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/squads/:squadID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "squads",
            ":squadID"
          ],
          "variable": [
            {
              "key": "squadID",
              "value": "5ed4e5977cc8a1daa90d56eb"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"data\": {\n        \"id\": \"5ed4e5977cc8a1daa90d56eb\",\n        \"name\": \"Devops Night Man Squad\",\n        \"slug\": \"devops-night-man-squad\",\n        \"members\": [\n            \"5df9d90aba2cb0c5a4f12d44\",\n            \"5df9d90aba2cb0c5a4f12d45\",\n            \"5df9d90aba2cb0c5a4f12d46\"\n        ],\n        \"organization\": {\n            \"id\": \"5ea962e35734157d01594951\",\n            \"name\": \"Avengers\",\n            \"slug\": \"avengers\"\n        }\n    }\n}"
    },
    {
      "name": "400 Bad Request",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/squads/:squadID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "squads",
            ":squadID"
          ],
          "variable": [
            {
              "key": "squadID",
              "value": "5ed4e5977cc8a1daa90d56eb"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 400,\n        \"error_message\": \"<string>\"\n    }\n}"
    },
    {
      "name": "401 Unauthorized",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/squads/:squadID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "squads",
            ":squadID"
          ],
          "variable": [
            {
              "key": "squadID",
              "value": "5ed4e5977cc8a1daa90d56eb"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 401,\n        \"error_message\": \"<string>\"\n    }\n}"
    },
    {
      "name": "403 Forbidden",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/squads/:squadID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "squads",
            ":squadID"
          ],
          "variable": [
            {
              "key": "squadID",
              "value": "5ed4e5977cc8a1daa90d56eb"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 403,\n        \"error_message\": \"<string>\"\n    }\n}"
    },
    {
      "name": "404 Not Found",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/squads/:squadID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "squads",
            ":squadID"
          ],
          "variable": [
            {
              "key": "squadID",
              "value": "5ed4e5977cc8a1daa90d56eb"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 404,\n        \"error_message\": \"<string>\"\n    }\n}"
    },
    {
      "name": "500 Internal Server Error",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"members\":[\n        \"5df9d90aba2cb0c5a4f12d44\",\n        \"5df9d90aba2cb0c5a4f12d45\",\n        \"5df9d90aba2cb0c5a4f12d46\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/squads/:squadID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "squads",
            ":squadID"
          ],
          "variable": [
            {
              "key": "squadID",
              "value": "5ed4e5977cc8a1daa90d56eb"
            }
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 500,\n        \"error_message\": \"<string>\"\n    }\n}"
    }
  ]
}