Chilkat Online Tools

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

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sV_Type
    String sName
    String sNamespace
    Integer j
    Integer iCount_j
    String sTypeType
    String sTypeName
    String sDoc
    Integer k
    Integer iCount_k
    String sDoc
    String sDefault
    Variant vJson1
    Handle hoJson1
    Integer iI1
    Integer iCount_i1
    String sStrVal
    String sName
    String sNamespace
    String sV_type
    Integer i
    Integer iCount_i
    String sTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComQuickGetSb Of hoHttp "https://domain.com/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema" vSbResponseBody To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComLastStatus Of hoHttp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComLastHeader Of hoHttp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    // 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

    Get ComStringOf Of hoJResp "name" To sName
    Get ComStringOf Of hoJResp "namespace" To sNamespace
    Get ComStringOf Of hoJResp "type" To sV_type
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "fields" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "fields[i].name" To sName
        Get ComStringOf Of hoJResp "fields[i].type.type" To sV_Type
        Get ComStringOf Of hoJResp "fields[i].type.name" To sName
        Get ComStringOf Of hoJResp "fields[i].type.namespace" To sNamespace
        Get ComStringOf Of hoJResp "fields[i].type" To sV_type
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "fields[i].type.fields" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "fields[i].type.fields[j].name" To sName
            Get ComStringOf Of hoJResp "fields[i].type.fields[j].type" To sV_type
            Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.type" To sTypeType
            Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.name" To sTypeName
            Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.doc" To sDoc
            Move 0 To k
            Get ComSizeOfArray Of hoJResp "fields[i].type.fields[j].type.fields" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJResp To k
                Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.fields[k].name" To sName
                Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.fields[k].type" To sV_type
                Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.fields[k].doc" To sDoc
                Get ComStringOf Of hoJResp "fields[i].type.fields[j].type.fields[k].default" To sDefault

                Get ComObjectOf Of hoJResp "fields[i].type.fields[j].type.fields[k]" To vJson1
                If (IsComObject(vJson1)) Begin
                    Get Create (RefClass(cComChilkatJsonObject)) To hoJson1
                    Set pvComObject Of hoJson1 To vJson1
                End
                Move 0 To iI1
                Get ComSizeOfArray Of hoJson1 "type" To iCount_i1
                While (iI1 < iCount_i1)
                    Set ComI Of hoJson1 To iI1
                    Get ComStringOf Of hoJson1 "type[i]" To sStrVal
                    Move (iI1 + 1) To iI1
                Loop

                Send Destroy of hoJson1
                Move (k + 1) To k
            Loop

            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure

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