Chilkat Online Tools

PureBasic / Braze Endpoints / Segment List

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

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

    CkJsonObject::ckUpdateInt(queryParams,"page",1)
    CkJsonObject::ckUpdateString(queryParams,"sort_direction","desc")

    ; Adds the "Authorization: Bearer {{api_key}}" header.
    CkHttp::setCkAuthToken(http, "{{api_key}}")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://rest.iad-01.braze.com/segments/list",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

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



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "page=1"
	-d "sort_direction=desc"
	-H "Authorization: Bearer {{api_key}}"
https://rest.iad-01.braze.com/segments/list

Postman Collection Item JSON

{
  "name": "Segment List",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{api_key}}"
      }
    ],
    "url": {
      "raw": "https://{{instance_url}}/segments/list?page=1&sort_direction=desc",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "segments",
        "list"
      ],
      "query": [
        {
          "key": "page",
          "value": "1",
          "description": "(Optional) Integer\n\nThe page of segments to return, defaults to 0 (returns the first set of up to 100)"
        },
        {
          "key": "sort_direction",
          "value": "desc",
          "description": "(Optional) String\n\nPass in the value `desc` to sort by creation time from newest to oldest. Pass in `asc` to sort from oldest to newest. If `sort_direction` is not included, the default order is oldest to newest."
        }
      ]
    },
    "description": "This endpoint allows you to export a list of segments, each of which will include its name, Segment API Identifier, and whether it has analytics tracking enabled. The segments are returned in groups of 100 sorted by time of creation (oldest to newest by default). Archived segments are not included.\n\n### Request Components\n- [Segment Identifier](https://www.braze.com/docs/api/identifier_types/)\n\n\n## Response\n\n```json\nContent-Type: application/json\nAuthorization: Bearer YOUR-REST-API-KEY\n{\n    \"message\": (required, string) the status of the export, returns 'success' when completed without errors,\n    \"segments\" : [\n        {\n            \"id\" : (string) Segment API Identifier,\n            \"name\" : (string) segment name,\n            \"analytics_tracking_enabled\" : (boolean) whether the segment has analytics tracking enabled,\n            \"tags\" : (array) tag names associated with the segment\n        },\n        ...\n    ]\n}\n```"
  },
  "response": [
  ]
}