Chilkat Online Tools

PowerBuilder / Datadog API Collection / Get team memberships

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_V_type
string ls_Role
string ls_Id
string ls_DataType
string ls_First
string ls_Last
string ls_V_Next
string ls_Prev
string ls_V_Self
string ls_First_offset
string ls_Last_offset
string ls_Limit
string ls_Next_offset
string ls_Offset
string ls_Prev_offset
string ls_Total
string ls_V_Type
integer i
integer li_Count_i

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_QueryParams = create oleobject
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_QueryParams.UpdateInt("page[size]",10)
loo_QueryParams.UpdateInt("page[number]",0)
loo_QueryParams.UpdateString("sort","email")
loo_QueryParams.UpdateString("filter[keyword]","<string>")

loo_Http.SetRequestHeader("Accept","application/json")

loo_Resp = loo_Http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v2/team/:team_id/memberships",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

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

// {
//   "data": [
//     {
//       "id": "<string>",
//       "type": "team_memberships",
//       "attributes": {
//         "role": "admin"
//       },
//       "relationships": {
//         "user": {
//           "data": {
//             "id": "<string>",
//             "type": "users"
//           }
//         }
//       }
//     },
//     {
//       "id": "<string>",
//       "type": "team_memberships",
//       "attributes": {
//         "role": "admin"
//       },
//       "relationships": {
//         "user": {
//           "data": {
//             "id": "<string>",
//             "type": "users"
//           }
//         }
//       }
//     }
//   ],
//   "links": {
//     "first": "<string>",
//     "last": "<string>",
//     "next": "<string>",
//     "prev": "<string>",
//     "self": "<string>"
//   },
//   "meta": {
//     "pagination": {
//       "first_offset": "<long>",
//       "last_offset": "<long>",
//       "limit": "<long>",
//       "next_offset": "<long>",
//       "offset": "<long>",
//       "prev_offset": "<long>",
//       "total": "<long>",
//       "type": "<string>"
//     }
//   }
// }

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

ls_First = loo_JResp.StringOf("links.first")
ls_Last = loo_JResp.StringOf("links.last")
ls_V_Next = loo_JResp.StringOf("links.next")
ls_Prev = loo_JResp.StringOf("links.prev")
ls_V_Self = loo_JResp.StringOf("links.self")
ls_First_offset = loo_JResp.StringOf("meta.pagination.first_offset")
ls_Last_offset = loo_JResp.StringOf("meta.pagination.last_offset")
ls_Limit = loo_JResp.StringOf("meta.pagination.limit")
ls_Next_offset = loo_JResp.StringOf("meta.pagination.next_offset")
ls_Offset = loo_JResp.StringOf("meta.pagination.offset")
ls_Prev_offset = loo_JResp.StringOf("meta.pagination.prev_offset")
ls_Total = loo_JResp.StringOf("meta.pagination.total")
ls_V_Type = loo_JResp.StringOf("meta.pagination.type")
i = 0
li_Count_i = loo_JResp.SizeOfArray("data")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Id = loo_JResp.StringOf("data[i].id")
    ls_V_type = loo_JResp.StringOf("data[i].type")
    ls_Role = loo_JResp.StringOf("data[i].attributes.role")
    ls_Id = loo_JResp.StringOf("data[i].relationships.user.data.id")
    ls_DataType = loo_JResp.StringOf("data[i].relationships.user.data.type")
    i = i + 1
loop


destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -G -d "page[size]=10"
	-d "page[number]=0"
	-d "sort=email"
	-d "filter[keyword]=%3Cstring%3E"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/team/:team_id/memberships

Postman Collection Item JSON

{
  "name": "Get team memberships",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships?page[size]=10&page[number]=0&sort=email&filter[keyword]=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "team",
        ":team_id",
        "memberships"
      ],
      "query": [
        {
          "key": "page[size]",
          "value": "10",
          "description": "Size for a given page. The maximum allowed value is 100."
        },
        {
          "key": "page[number]",
          "value": "0",
          "description": "Specific page number to return."
        },
        {
          "key": "sort",
          "value": "email",
          "description": "Specifies the order of returned team memberships"
        },
        {
          "key": "filter[keyword]",
          "value": "<string>",
          "description": "Search query, can be user email or name"
        }
      ],
      "variable": [
        {
          "key": "team_id",
          "value": "<string>"
        }
      ]
    },
    "description": "Get a paginated list of members for a team"
  },
  "response": [
    {
      "name": "Represents a user's association to a team",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships?page[size]=10&page[number]=0&sort=email&filter[keyword]=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team",
            ":team_id",
            "memberships"
          ],
          "query": [
            {
              "key": "page[size]",
              "value": "10",
              "description": "Size for a given page. The maximum allowed value is 100."
            },
            {
              "key": "page[number]",
              "value": "0",
              "description": "Specific page number to return."
            },
            {
              "key": "sort",
              "value": "email",
              "description": "Specifies the order of returned team memberships"
            },
            {
              "key": "filter[keyword]",
              "value": "<string>",
              "description": "Search query, can be user email or name"
            }
          ],
          "variable": [
            {
              "key": "team_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"id\": \"<string>\",\n      \"type\": \"team_memberships\",\n      \"attributes\": {\n        \"role\": \"admin\"\n      },\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    },\n    {\n      \"id\": \"<string>\",\n      \"type\": \"team_memberships\",\n      \"attributes\": {\n        \"role\": \"admin\"\n      },\n      \"relationships\": {\n        \"user\": {\n          \"data\": {\n            \"id\": \"<string>\",\n            \"type\": \"users\"\n          }\n        }\n      }\n    }\n  ],\n  \"links\": {\n    \"first\": \"<string>\",\n    \"last\": \"<string>\",\n    \"next\": \"<string>\",\n    \"prev\": \"<string>\",\n    \"self\": \"<string>\"\n  },\n  \"meta\": {\n    \"pagination\": {\n      \"first_offset\": \"<long>\",\n      \"last_offset\": \"<long>\",\n      \"limit\": \"<long>\",\n      \"next_offset\": \"<long>\",\n      \"offset\": \"<long>\",\n      \"prev_offset\": \"<long>\",\n      \"total\": \"<long>\",\n      \"type\": \"<string>\"\n    }\n  }\n}"
    },
    {
      "name": "API error response.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships?page[size]=10&page[number]=0&sort=email&filter[keyword]=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team",
            ":team_id",
            "memberships"
          ],
          "query": [
            {
              "key": "page[size]",
              "value": "10",
              "description": "Size for a given page. The maximum allowed value is 100."
            },
            {
              "key": "page[number]",
              "value": "0",
              "description": "Specific page number to return."
            },
            {
              "key": "sort",
              "value": "email",
              "description": "Specifies the order of returned team memberships"
            },
            {
              "key": "filter[keyword]",
              "value": "<string>",
              "description": "Search query, can be user email or name"
            }
          ],
          "variable": [
            {
              "key": "team_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/team/:team_id/memberships?page[size]=10&page[number]=0&sort=email&filter[keyword]=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "team",
            ":team_id",
            "memberships"
          ],
          "query": [
            {
              "key": "page[size]",
              "value": "10",
              "description": "Size for a given page. The maximum allowed value is 100."
            },
            {
              "key": "page[number]",
              "value": "0",
              "description": "Specific page number to return."
            },
            {
              "key": "sort",
              "value": "email",
              "description": "Specifies the order of returned team memberships"
            },
            {
              "key": "filter[keyword]",
              "value": "<string>",
              "description": "Search query, can be user email or name"
            }
          ],
          "variable": [
            {
              "key": "team_id"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}