Chilkat Online Tools

PureBasic / MeiliSearch v0.24 / Update settings

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"searchableAttributes[0]","title")
    CkJsonObject::ckUpdateString(json,"searchableAttributes[1]","author")
    CkJsonObject::ckUpdateString(json,"stopWords[0]","of")
    CkJsonObject::ckUpdateString(json,"stopWords[1]","the")
    CkJsonObject::ckUpdateString(json,"displayedAttributes[0]","title")
    CkJsonObject::ckUpdateString(json,"displayedAttributes[1]","author")
    CkJsonObject::ckUpdateString(json,"displayedAttributes[2]","genre")
    CkJsonObject::ckUpdateString(json,"displayedAttributes[3]","price")
    CkJsonObject::ckUpdateString(json,"filterableAttributes[0]","genre")
    CkJsonObject::ckUpdateString(json,"filterableAttributes[1]","price")
    CkJsonObject::ckUpdateString(json,"sortableAttributes[0]","price")

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
    CkHttp::ckSetRequestHeader(http,"X-Meili-Api-Key","masterKey")

    resp.i = CkHttp::ckPostJson3(http,"http://localhost:7700/indexes/indexUID/settings","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

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": [
  ]
}