Swift3 / MeiliSearch v0.24 / Add or update documents
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// [
// {
// "id": 2,
// "author": "J. Austen",
// "date": "1813"
// }
// ]
let jarr = CkoJsonArray()!
jarr.addObject(at: -1)
var jsonObj_1: CkoJsonObject? = jarr.object(at: jarr.size.intValue - 1)
jsonObj_1!.updateInt("id", value: 2)
jsonObj_1!.update("author", value: "J. Austen")
jsonObj_1!.update("date", value: "1813")
jsonObj_1 = nil
http.setRequestHeader("X-Meili-Api-Key", value: "masterKey")
let sbRequestBody = CkoStringBuilder()!
jarr.emitSb(sbRequestBody)
var resp: CkoHttpResponse? = http.pTextSb("PUT", url: "http://localhost:7700/indexes/indexUID/documents", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
Curl Command
curl -X PUT
-H "X-Meili-Api-Key: masterKey"
-d '[
{
"id": 2,
"author": "J. Austen",
"date": "1813"
}
]'
http://localhost:7700/indexes/indexUID/documents
Postman Collection Item JSON
{
"name": "Add or update documents",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "[\n {\n\t\"id\": 2,\n\t\"author\": \"J. Austen\",\n\t\"date\": \"1813\"\n }\n]",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/indexes/{{indexUID}}/documents",
"host": [
"{{url}}"
],
"path": [
"indexes",
"{{indexUID}}",
"documents"
],
"query": [
{
"key": "primaryKey",
"value": "id",
"disabled": true
}
]
}
},
"response": [
]
}