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 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
Set ComBasicAuth Of hoHttp To True
Set ComLogin Of hoHttp To "username"
Set ComPassword Of hoHttp To "password"
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "author": {
// "type": "user",
// "userId": "5963c0d619a30a2e00de36b8"
// },
// "type": "conversation:read"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "author.type" "user" To iSuccess
Get ComUpdateString Of hoJson "author.userId" "5963c0d619a30a2e00de36b8" To iSuccess
Get ComUpdateString Of hoJson "type" "conversation:read" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://domain.com/" "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
End_Procedure
Curl Command
curl -X POST
-u 'username:password'
-H "Content-Type: application/json"
-d '{
"author": {
"type": "user",
"userId": "5963c0d619a30a2e00de36b8"
},
"type": "conversation:read"
}'
https://domain.com/
Postman Collection Item JSON
{
"name": "Post Activity",
"_postman_id": "5c795888-a93c-412f-9a6a-08f8f9363920",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"author\": {\n \"type\": \"user\",\n \"userId\": \"5963c0d619a30a2e00de36b8\"\n },\n \"type\": \"conversation:read\"\n}"
},
"url": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}/activity",
"description": "Notify Sunshine Conversations of different conversation activities. Supported activity types are:\n* Typing activity\n* Conversation read event\n"
},
"response": [
{
"id": "0b684a54-f943-4b76-ac08-2dc014091c85",
"name": "Ok",
"originalRequest": {
"method": "POST",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"author\": {\n \"type\": \"user\",\n \"userId\": \"5963c0d619a30a2e00de36b8\"\n },\n \"type\": \"conversation:read\"\n}"
},
"url": {
"raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId/activity",
"host": [
"{{baseUrl}}"
],
"path": [
"v2",
"apps",
":appId",
"conversations",
":conversationId",
"activity"
],
"variable": [
{
"key": "appId"
},
{
"key": "conversationId"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{}"
}
]
}