Chilkat Online Tools

Foxpro / Salesforce Platform APIs / Platform Event Schema by Event Name

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcV_Type
LOCAL lcName
LOCAL lcNamespace
LOCAL j
LOCAL lnCount_j
LOCAL lcTypeType
LOCAL lcTypeName
LOCAL lcDoc
LOCAL k
LOCAL lnCount_k
LOCAL lcDoc
LOCAL lcDefault
LOCAL loJson1
LOCAL lnI1
LOCAL lnCount_i1
LOCAL lcStrVal
LOCAL lcName
LOCAL lcNamespace
LOCAL lcV_type
LOCAL i
LOCAL lnCount_i

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loHttp.SetRequestHeader("Content-Type","application/json")

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://domain.com/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loSbResponseBody
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loHttp
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

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

* {
*   "name": "Sample__e",
*   "namespace": "com.sforce.eventbus",
*   "type": "expanded-record",
*   "fields": [
*     {
*       "name": "data",
*       "type": {
*         "type": "record",
*         "name": "Data",
*         "namespace": "",
*         "fields": [
*           {
*             "name": "schema",
*             "type": "string"
*           },
*           {
*             "name": "payload",
*             "type": {
*               "type": "record",
*               "name": "Payload",
*               "doc": "",
*               "fields": [
*                 {
*                   "name": "CreatedDate",
*                   "type": "string",
*                   "doc": "CreatedDate:DateTime"
*                 },
*                 {
*                   "name": "CreatedById",
*                   "type": "string",
*                   "doc": "CreatedBy:EntityId"
*                 },
*                 {
*                   "name": "Message__c",
*                   "type": [
*                     "null",
*                     "string"
*                   ],
*                   "doc": "Data:Text:00N4H00000Ecs0G",
*                   "default": null
*                 }
*               ]
*             }
*           },
*           {
*             "name": "event",
*             "type": {
*               "type": "record",
*               "name": "Event",
*               "fields": [
*                 {
*                   "name": "replayId",
*                   "type": "long"
*                 }
*               ]
*             }
*           }
*         ]
*       }
*     },
*     {
*       "name": "channel",
*       "type": "string"
*     }
*   ]
* }

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

lcName = loJResp.StringOf("name")
lcNamespace = loJResp.StringOf("namespace")
lcV_type = loJResp.StringOf("type")
i = 0
lnCount_i = loJResp.SizeOfArray("fields")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcName = loJResp.StringOf("fields[i].name")
    lcV_Type = loJResp.StringOf("fields[i].type.type")
    lcName = loJResp.StringOf("fields[i].type.name")
    lcNamespace = loJResp.StringOf("fields[i].type.namespace")
    lcV_type = loJResp.StringOf("fields[i].type")
    j = 0
    lnCount_j = loJResp.SizeOfArray("fields[i].type.fields")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcName = loJResp.StringOf("fields[i].type.fields[j].name")
        lcV_type = loJResp.StringOf("fields[i].type.fields[j].type")
        lcTypeType = loJResp.StringOf("fields[i].type.fields[j].type.type")
        lcTypeName = loJResp.StringOf("fields[i].type.fields[j].type.name")
        lcDoc = loJResp.StringOf("fields[i].type.fields[j].type.doc")
        k = 0
        lnCount_k = loJResp.SizeOfArray("fields[i].type.fields[j].type.fields")
        DO WHILE k < lnCount_k
            loJResp.K = k
            lcName = loJResp.StringOf("fields[i].type.fields[j].type.fields[k].name")
            lcV_type = loJResp.StringOf("fields[i].type.fields[j].type.fields[k].type")
            lcDoc = loJResp.StringOf("fields[i].type.fields[j].type.fields[k].doc")
            lcDefault = loJResp.StringOf("fields[i].type.fields[j].type.fields[k].default")

            loJson1 = loJResp.ObjectOf("fields[i].type.fields[j].type.fields[k]")
            lnI1 = 0
            lnCount_i1 = loJson1.SizeOfArray("type")
            DO WHILE lnI1 < lnCount_i1
                loJson1.I = lnI1
                lcStrVal = loJson1.StringOf("type[i]")
                lnI1 = lnI1 + 1
            ENDDO
            RELEASE loJson1
            k = k + 1
        ENDDO
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
https://domain.com/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema

Postman Collection Item JSON

{
  "name": "Platform Event Schema by Event Name",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "sobjects",
        ":EVENT_NAME",
        "eventSchema"
      ],
      "query": [
        {
          "key": "payloadFormat",
          "value": "",
          "description": "(Optional query parameter. Available in API version 43.0 and later.) The format of the returned event schema. This parameter can take one of the following values.\nEXPANDED—The JSON representation of the event schema, which is the default format when payloadFormat is not specified in API version 43.0 and later.\nCOMPACT—A format that adheres to the open-source Apache Avro specification for the record complex type (see Apache Avro Format). Subscribers use the compact schema format to deserialize compact events received in binary form.",
          "disabled": true
        }
      ],
      "variable": [
        {
          "key": "EVENT_NAME",
          "value": "",
          "description": "API Name of the event"
        }
      ]
    },
    "description": "Set, reset, or get information about a user password. This resource is available in REST API version 24.0 and later."
  },
  "response": [
    {
      "name": "Platform Event Schema by Event Name",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "sobjects",
            ":EVENT_NAME",
            "eventSchema"
          ],
          "query": [
            {
              "key": "payloadFormat",
              "value": "",
              "description": "(Optional query parameter. Available in API version 43.0 and later.) The format of the returned event schema. This parameter can take one of the following values.\nEXPANDED—The JSON representation of the event schema, which is the default format when payloadFormat is not specified in API version 43.0 and later.\nCOMPACT—A format that adheres to the open-source Apache Avro specification for the record complex type (see Apache Avro Format). Subscribers use the compact schema format to deserialize compact events received in binary form.",
              "disabled": true
            }
          ],
          "variable": [
            {
              "key": "EVENT_NAME",
              "value": "Sample__e",
              "description": "API Name of the event"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Mon, 03 Jul 2023 13:06:08 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=2/15000"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"name\": \"Sample__e\",\n    \"namespace\": \"com.sforce.eventbus\",\n    \"type\": \"expanded-record\",\n    \"fields\": [\n        {\n            \"name\": \"data\",\n            \"type\": {\n                \"type\": \"record\",\n                \"name\": \"Data\",\n                \"namespace\": \"\",\n                \"fields\": [\n                    {\n                        \"name\": \"schema\",\n                        \"type\": \"string\"\n                    },\n                    {\n                        \"name\": \"payload\",\n                        \"type\": {\n                            \"type\": \"record\",\n                            \"name\": \"Payload\",\n                            \"doc\": \"\",\n                            \"fields\": [\n                                {\n                                    \"name\": \"CreatedDate\",\n                                    \"type\": \"string\",\n                                    \"doc\": \"CreatedDate:DateTime\"\n                                },\n                                {\n                                    \"name\": \"CreatedById\",\n                                    \"type\": \"string\",\n                                    \"doc\": \"CreatedBy:EntityId\"\n                                },\n                                {\n                                    \"name\": \"Message__c\",\n                                    \"type\": [\n                                        \"null\",\n                                        \"string\"\n                                    ],\n                                    \"doc\": \"Data:Text:00N4H00000Ecs0G\",\n                                    \"default\": null\n                                }\n                            ]\n                        }\n                    },\n                    {\n                        \"name\": \"event\",\n                        \"type\": {\n                            \"type\": \"record\",\n                            \"name\": \"Event\",\n                            \"fields\": [\n                                {\n                                    \"name\": \"replayId\",\n                                    \"type\": \"long\"\n                                }\n                            ]\n                        }\n                    }\n                ]\n            }\n        },\n        {\n            \"name\": \"channel\",\n            \"type\": \"string\"\n        }\n    ]\n}"
    }
  ]
}