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.
// {
// "searchableAttributes": [
// "title",
// "author"
// ],
// "stopWords": [
// "of",
// "the"
// ],
// "displayedAttributes": [
// "title",
// "author",
// "genre",
// "price"
// ],
// "filterableAttributes": [
// "genre",
// "price"
// ],
// "sortableAttributes": [
// "price"
// ]
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"searchableAttributes[0]",L"title");
CkJsonObjectW_UpdateString(json,L"searchableAttributes[1]",L"author");
CkJsonObjectW_UpdateString(json,L"stopWords[0]",L"of");
CkJsonObjectW_UpdateString(json,L"stopWords[1]",L"the");
CkJsonObjectW_UpdateString(json,L"displayedAttributes[0]",L"title");
CkJsonObjectW_UpdateString(json,L"displayedAttributes[1]",L"author");
CkJsonObjectW_UpdateString(json,L"displayedAttributes[2]",L"genre");
CkJsonObjectW_UpdateString(json,L"displayedAttributes[3]",L"price");
CkJsonObjectW_UpdateString(json,L"filterableAttributes[0]",L"genre");
CkJsonObjectW_UpdateString(json,L"filterableAttributes[1]",L"price");
CkJsonObjectW_UpdateString(json,L"sortableAttributes[0]",L"price");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"X-Meili-Api-Key",L"masterKey");
resp = CkHttpW_PostJson3(http,L"http://localhost:7700/indexes/indexUID/settings",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 "X-Meili-Api-Key: masterKey"
-H "Content-Type: application/json"
-d '{
"searchableAttributes": ["title", "author"],
"stopWords": ["of", "the"],
"displayedAttributes": ["title", "author", "genre", "price"],
"filterableAttributes": ["genre", "price"],
"sortableAttributes": ["price"]
}'
http://localhost:7700/indexes/indexUID/settings
Postman Collection Item JSON
{
"name": "Update settings",
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"content-type": true
}
},
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"searchableAttributes\": [\"title\", \"author\"],\n\t\"stopWords\": [\"of\", \"the\"],\n \"displayedAttributes\": [\"title\", \"author\", \"genre\", \"price\"],\n \"filterableAttributes\": [\"genre\", \"price\"],\n \"sortableAttributes\": [\"price\"]\n}"
},
"url": {
"raw": "{{url}}/indexes/{{indexUID}}/settings",
"host": [
"{{url}}"
],
"path": [
"indexes",
"{{indexUID}}",
"settings"
]
}
},
"response": [
]
}