Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "my first watchlist",
// "symbols": [
// "AAPL",
// "LMND",
// "PLTR",
// "AMZN",
// "CSCO",
// "A"
// ]
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"name",L"my first watchlist");
CkJsonObjectW_UpdateString(json,L"symbols[0]",L"AAPL");
CkJsonObjectW_UpdateString(json,L"symbols[1]",L"LMND");
CkJsonObjectW_UpdateString(json,L"symbols[2]",L"PLTR");
CkJsonObjectW_UpdateString(json,L"symbols[3]",L"AMZN");
CkJsonObjectW_UpdateString(json,L"symbols[4]",L"CSCO");
CkJsonObjectW_UpdateString(json,L"symbols[5]",L"A");
CkHttpW_SetRequestHeader(http,L"Apca-Api-Secret-Key",L"{{APCA_API_SECRET_KEY}}");
CkHttpW_SetRequestHeader(http,L"Apca-Api-Key-Id",L"{{APCA_API_KEY_ID}}");
resp = CkHttpW_PostJson3(http,L"https://domain.com/v2/watchlists",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
}
Curl Command
curl -X POST
-H "Apca-Api-Key-Id: {{APCA_API_KEY_ID}}"
-H "Apca-Api-Secret-Key: {{APCA_API_SECRET_KEY}}"
-d '{
"name": "my first watchlist",
"symbols": ["AAPL","LMND","PLTR","AMZN","CSCO","A"]
}'
https://domain.com/v2/watchlists
Postman Collection Item JSON
{
"name": "Watchlist",
"request": {
"method": "POST",
"header": [
{
"key": "Apca-Api-Key-Id",
"value": "{{APCA_API_KEY_ID}}",
"type": "text"
},
{
"key": "Apca-Api-Secret-Key",
"value": "{{APCA_API_SECRET_KEY}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"my first watchlist\",\n \"symbols\": [\"AAPL\",\"LMND\",\"PLTR\",\"AMZN\",\"CSCO\",\"A\"]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{HOST}}/v2/watchlists",
"host": [
"{{HOST}}"
],
"path": [
"v2",
"watchlists"
]
},
"description": "| Parameter | Type | Requirement |\n|-------------|---------------|:-----------:|\n| `name` | string | Required |\n| `symbols` | array[string] | Optional |"
},
"response": [
]
}