Chilkat Online Tools

ERROR!

------------------- GenerateCode ----------------------
---- begin chilkat script ----
// This example assumes the Chilkat API to have been previously unlocked.
// See {{-global_unlock:::Global Unlock Sample-}} for sample code.

new Http http;
ckbool success;

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

new StringBuilder sbResponseBody;
success = http.QuickGetSb("https://domain.com/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema",sbResponseBody);
if (success == ckfalse) {
    println http.LastErrorText;
    return;
}

new JsonObject jResp;
call jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = ckfalse;

println "Response Body:";
println jResp.Emit();

int respStatusCode = http.LastStatus;
println "Response Status Code = ",respStatusCode;
if (respStatusCode >= 400) {
    println "Response Header:";
    println http.LastHeader;
    println "Failed.";
    return;
}

// 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: {{.https://tools.chilkat.io/jsonParse|||Generate JSON Parsing Code.}}

#ifdef IS_C_CPP
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
#undef IS_C_CPP

JsonObject json1;
string strVal;

string name = jResp.StringOf("name");
namespace = jResp.StringOf("namespace");
v_type = jResp.StringOf("type");
int i = 0;
int count_i = jResp.SizeOfArray("fields");
while i < count_i {
    jResp.I = i;
    name = jResp.StringOf("fields[i].name");
    v_Type = jResp.StringOf("fields[i].type.type");
    Name = jResp.StringOf("fields[i].type.name");
    Namespace = jResp.StringOf("fields[i].type.namespace");
    v_type = jResp.StringOf("fields[i].type");
    j = 0;
    count_j = jResp.SizeOfArray("fields[i].type.fields");
    while j < count_j {
        jResp.J = j;
        name = jResp.StringOf("fields[i].type.fields[j].name");
        v_type = jResp.StringOf("fields[i].type.fields[j].type");
        typeType = jResp.StringOf("fields[i].type.fields[j].type.type");
        typeName = jResp.StringOf("fields[i].type.fields[j].type.name");
        Doc = jResp.StringOf("fields[i].type.fields[j].type.doc");
        k = 0;
        count_k = jResp.SizeOfArray("fields[i].type.fields[j].type.fields");
        while k < count_k {
            jResp.K = k;
            name = jResp.StringOf("fields[i].type.fields[j].type.fields[k].name");
            v_type = jResp.StringOf("fields[i].type.fields[j].type.fields[k].type");
            doc = jResp.StringOf("fields[i].type.fields[j].type.fields[k].doc");
            default = jResp.StringOf("fields[i].type.fields[j].type.fields[k].default");

            json1 = jResp.ObjectOf("fields[i].type.fields[j].type.fields[k]");
            i1 = 0;
            count_i1 = json1.SizeOfArray("type");
            while i1 < count_i1 {
                json1.I = i1;
                strVal = json1.StringOf("type[i]");
                i1 = i1 + 1;
            }
            delete json1;
            k = k + 1;
        }
        j = j + 1;
    }
    i = i + 1;
}



---- end chilkat script ----

C# / Salesforce Platform APIs / Platform Event Schema by Event Name

Back to Collection Items

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

Chilkat.Http http = new Chilkat.Http();
bool success;

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

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
success = http.QuickGetSb("https://domain.com/services/data/v{{version}}/sobjects/:EVENT_NAME/eventSchema",sbResponseBody);
if (success == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());

int respStatusCode = http.LastStatus;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(http.LastHeader);
    Debug.WriteLine("Failed.");
    return;
}

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

Chilkat.JsonObject json1 = null;
string strVal;

string name = jResp.StringOf("name");
ERROR: Undefined variable(namespace)

ERROR: Undefined variable(v_type)

int i = 0;
int count_i = jResp.SizeOfArray("fields");
while (i < count_i) {
    jResp.I = i;
    name = jResp.StringOf("fields[i].name");
ERROR: Undefined variable(v_Type)

ERROR: Undefined variable(Name)

ERROR: Undefined variable(Namespace)

ERROR: Undefined variable(v_type)

ERROR: Undefined variable(j)

ERROR: Undefined variable(count_j)

ERROR: Undefined variable(j)
ERROR: Undefined variable(count_j)
    while (j < count_j) {
ERROR: Undefined variable(j)
ERROR: No et type for RHS expression.

        name = jResp.StringOf("fields[i].type.fields[j].name");
ERROR: Undefined variable(v_type)

ERROR: Undefined variable(typeType)

ERROR: Undefined variable(typeName)

ERROR: Undefined variable(Doc)

ERROR: Undefined variable(k)

ERROR: Undefined variable(count_k)

ERROR: Undefined variable(k)
ERROR: Undefined variable(count_k)
        while (k < count_k) {
ERROR: Undefined variable(k)
ERROR: No et type for RHS expression.

            name = jResp.StringOf("fields[i].type.fields[j].type.fields[k].name");
ERROR: Undefined variable(v_type)

ERROR: Undefined variable(doc)

ERROR: Undefined variable(default)

            json1 = jResp.ObjectOf("fields[i].type.fields[j].type.fields[k]");
ERROR: Undefined variable(i1)

ERROR: Undefined variable(count_i1)

ERROR: Undefined variable(i1)
ERROR: Undefined variable(count_i1)
            while (i1 < count_i1) {
ERROR: Undefined variable(i1)
ERROR: No et type for RHS expression.

                strVal = json1.StringOf("type[i]");
ERROR: Undefined variable(i1)
ERROR: Missing et type attribute (b)
ERROR: Undefined variable(i1)

            }

ERROR: Undefined variable(k)
ERROR: Missing et type attribute (b)
ERROR: Undefined variable(k)

        }

ERROR: Undefined variable(j)
ERROR: Missing et type attribute (b)
ERROR: Undefined variable(j)

    }

    i = i + 1;
}

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