Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sId
String sValue
Integer iTotalCount
Boolean iHasNextPage
Boolean iHasPreviousPage
String sStartCursor
String sEndCursor
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// 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
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "query": "query accountsWithCursors($first: Int, $after: String) {\n uiapi {\n query {\n Account(first: $first, after: $after) {\n edges {\n node {\n Id\n Name {\n value\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}",
// "variables": "{\n \"first\": 3,\n \"after\": null\n}"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "query" "query accountsWithCursors($first: Int, $after: String) {" + (character(10)) + " uiapi {" + (character(10)) + " query {" + (character(10)) + " Account(first: $first, after: $after) {" + (character(10)) + " edges {" + (character(10)) + " node {" + (character(10)) + " Id" + (character(10)) + " Name {" + (character(10)) + " value" + (character(10)) + " }" + (character(10)) + " }" + (character(10)) + " }" + (character(10)) + " totalCount" + (character(10)) + " pageInfo {" + (character(10)) + " hasNextPage" + (character(10)) + " hasPreviousPage" + (character(10)) + " startCursor" + (character(10)) + " endCursor" + (character(10)) + " }" + (character(10)) + " }" + (character(10)) + " }" + (character(10)) + " }" + (character(10)) + "}" To iSuccess
Get ComUpdateString Of hoJson "variables" '{' + (character(10)) + ' "first": 3,' + (character(10)) + ' "after": null' + (character(10)) + '}' To iSuccess
// Adds the "Authorization: Bearer <access_token>" header.
Set ComAuthToken Of hoHttp To "<access_token>"
Send ComSetRequestHeader To hoHttp "X-Chatter-Entity-Encoding" "false"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://domain.com/services/data/v{{version}}/graphql" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
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 ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "uiapi": {
// "query": {
// "Account": {
// "edges": [
// {
// "node": {
// "Id": "0014H00004CXfY8QAL",
// "Name": {
// "value": "An Account"
// }
// }
// },
// {
// "node": {
// "Id": "0014H00002E6wi6QAB",
// "Name": {
// "value": "Sample Account"
// }
// }
// },
// {
// "node": {
// "Id": "0014H00002x6HUhQAM",
// "Name": {
// "value": "ACME Inc."
// }
// }
// }
// ],
// "totalCount": 524,
// "pageInfo": {
// "hasNextPage": true,
// "hasPreviousPage": false,
// "startCursor": "djE6MA==",
// "endCursor": "djE6Mg=="
// }
// }
// }
// }
// },
// "errors": [
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Get ComIntOf Of hoJResp "data.uiapi.query.Account.totalCount" To iTotalCount
Get ComBoolOf Of hoJResp "data.uiapi.query.Account.pageInfo.hasNextPage" To iHasNextPage
Get ComBoolOf Of hoJResp "data.uiapi.query.Account.pageInfo.hasPreviousPage" To iHasPreviousPage
Get ComStringOf Of hoJResp "data.uiapi.query.Account.pageInfo.startCursor" To sStartCursor
Get ComStringOf Of hoJResp "data.uiapi.query.Account.pageInfo.endCursor" To sEndCursor
Move 0 To i
Get ComSizeOfArray Of hoJResp "data.uiapi.query.Account.edges" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "data.uiapi.query.Account.edges[i].node.Id" To sId
Get ComStringOf Of hoJResp "data.uiapi.query.Account.edges[i].node.Name.value" To sValue
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "errors" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
End_Procedure
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "X-Chatter-Entity-Encoding: false"
--data-raw '{"query":"query accountsWithCursors($first: Int, $after: String) {\n uiapi {\n query {\n Account(first: $first, after: $after) {\n edges {\n node {\n Id\n Name {\n value\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}","variables":"{\n \"first\": 3,\n \"after\": null\n}"}'
https://domain.com/services/data/v{{version}}/graphql
Postman Collection Item JSON
{
"name": "Accounts with Cursors (Pagination)",
"request": {
"method": "POST",
"header": [
{
"key": "X-Chatter-Entity-Encoding",
"value": "false",
"type": "text"
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "query accountsWithCursors($first: Int, $after: String) {\n uiapi {\n query {\n Account(first: $first, after: $after) {\n edges {\n node {\n Id\n Name {\n value\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}",
"variables": "{\n \"first\": 3,\n \"after\": null\n}"
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/graphql",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"graphql"
]
}
},
"response": [
{
"name": "Accounts with Cursors (Pagination)",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "X-Chatter-Entity-Encoding",
"value": "false"
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "query accountsWithCursors($first: Int, $after: String) {\n uiapi {\n query {\n Account(first: $first, after: $after) {\n edges {\n node {\n Id\n Name {\n value\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n}",
"variables": "{\n \"first\": 3,\n \"after\": null\n}"
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/graphql",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"graphql"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Fri, 06 Oct 2023 09:05:20 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": "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 \"data\": {\n \"uiapi\": {\n \"query\": {\n \"Account\": {\n \"edges\": [\n {\n \"node\": {\n \"Id\": \"0014H00004CXfY8QAL\",\n \"Name\": {\n \"value\": \"An Account\"\n }\n }\n },\n {\n \"node\": {\n \"Id\": \"0014H00002E6wi6QAB\",\n \"Name\": {\n \"value\": \"Sample Account\"\n }\n }\n },\n {\n \"node\": {\n \"Id\": \"0014H00002x6HUhQAM\",\n \"Name\": {\n \"value\": \"ACME Inc.\"\n }\n }\n }\n ],\n \"totalCount\": 524,\n \"pageInfo\": {\n \"hasNextPage\": true,\n \"hasPreviousPage\": false,\n \"startCursor\": \"djE6MA==\",\n \"endCursor\": \"djE6Mg==\"\n }\n }\n }\n }\n },\n \"errors\": []\n}"
}
]
}