Chilkat Online Tools

VBScript / Creatio API / Get a field of object collection instance by Id

Back to Collection Items

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

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

set http = CreateObject("Chilkat_9_5_0.Http")

http.SetRequestHeader "ForceUseSession","true"
http.SetRequestHeader "BPMCSRF","{{BPMCSRF}}"

set sbResponseBody = CreateObject("Chilkat_9_5_0.StringBuilder")
success = http.QuickGetSb("https://myserver.com/0/odata/Collection1(Id)/Field1",sbResponseBody)
If (success = 0) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

set jResp = CreateObject("Chilkat_9_5_0.JsonObject")
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0

outFile.WriteLine("Response Body:")
outFile.WriteLine(jResp.Emit())

respStatusCode = http.LastStatus
outFile.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
    outFile.WriteLine("Response Header:")
    outFile.WriteLine(http.LastHeader)
    outFile.WriteLine("Failed.")
    WScript.Quit
End If

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

' {
'   "@odata.context": "https://myserver.com/0/odata/$metadata#Employee(c31c7862-fe33-4a13-9bbc-0943fa08fd02)/Name",
'   "value": "William Walker"
' }

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

odata_context = jResp.StringOf("""@odata.context""")
value = jResp.StringOf("value")

outFile.Close

Curl Command

curl -X GET
	-H "ForceUseSession: true"
	-H "BPMCSRF: {{BPMCSRF}}"
https://myserver.com/0/odata/Collection1(Id)/Field1

Postman Collection Item JSON

{
  "name": "Get a field of object collection instance by Id",
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "ForceUseSession",
        "type": "text",
        "value": "true"
      },
      {
        "key": "BPMCSRF",
        "type": "text",
        "value": "{{BPMCSRF}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": ""
    },
    "url": {
      "raw": "{{BaseURI}}/0/odata/{{CollectionName1}}({{ObjectId1}})/{{FieldName1}}",
      "host": [
        "{{BaseURI}}"
      ],
      "path": [
        "0",
        "odata",
        "{{CollectionName1}}({{ObjectId1}})",
        "{{FieldName1}}"
      ]
    },
    "description": "Request for getting a specific field value by the Id of an object collection instance."
  },
  "response": [
    {
      "name": "[200] Gets a field of an object collection instance by Id",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "type": "text",
            "value": "application/json"
          },
          {
            "key": "Content-Type",
            "type": "text",
            "value": "application/json; charset=utf-8"
          },
          {
            "key": "ForceUseSession",
            "type": "text",
            "value": "true"
          },
          {
            "key": "BPMCSRF",
            "type": "text",
            "value": "{{BPMCSRF}}"
          }
        ],
        "url": {
          "raw": "https://myserver.com/0/odata/Employee(c31c7862-fe33-4a13-9bbc-0943fa08fd02)/Name",
          "protocol": "https",
          "host": [
            "myserver",
            "com"
          ],
          "path": [
            "0",
            "odata",
            "Employee(c31c7862-fe33-4a13-9bbc-0943fa08fd02)",
            "Name"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Content-Type",
          "value": "application/json; odata.metadata=minimal"
        },
        {
          "key": "Expires",
          "value": "-1"
        },
        {
          "key": "Server",
          "value": "Microsoft-IIS/10.0"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "X-AspNet-Version",
          "value": "4.0.30319"
        },
        {
          "key": "X-Powered-By",
          "value": "ASP.NET"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "Date",
          "value": "Wed, 26 Feb 2020 14:50:43 GMT"
        },
        {
          "key": "Content-Length",
          "value": "135"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"@odata.context\": \"https://myserver.com/0/odata/$metadata#Employee(c31c7862-fe33-4a13-9bbc-0943fa08fd02)/Name\",\n    \"value\": \"William Walker\"\n}"
    }
  ]
}