Hello everyone,
I would like to be able to make an api call to update a spefic record/row,setting one of its field to a value. I have looked at the docs here but the structure of the payload to send is really difficult to digest. Just how would I prepare this http PUT request to update the collect field for a record whose survey field value is "strategy"? The lookup table(named survey_manager) has two fields, survey and collect.
I also noticed that I would need an ID for a record to update, but my attempt to get to the specific record also failed. Can I do something like this on this endpoint? Currently I am getting all records back. Better docs somewhere for quering this endpoint?:
https://www.commcarehq.org/a/mydomain/api/v0.5/lookup_table_item?data_type_id=59d698fea39144f187ba878dbd30bce6&survey=strategy
@Simon_Kelly Also, I tried to send a POST request to this endpoint https://www.commcarehq.org/a/mydomain/api/v0.5/lookup_table_item, in an attempt to insert a new record in the lookup table, with the payload as below but I am getting a 301 permanently moved
response. Any pointers? Here is my payload:
{
"data_type_id": "59d698fea39154f197ba878dbd30bce6",
"fields": {
"survey": {
"field_list": [
{
"field_value": "baseline",
"properties": {}
}
]
},
"collect": {
"field_list": [
{
"field_value": "yes",
"properties": {}
}
]
}
}
}
I further tried to send a PUT request to this endpoint https://www.commcarehq.org/a/mydomain/api/v0.5/lookup_table_item/7aed6de9b360458e8fd63365d2d61f3b, but I am still getting the same 301 Moved permanently
response. Here is the payload for the PUT request:
{
"data_type_id": "59d698fea39144f197ba878dbd30bce4",
"fields": {
"collect": {
"field_list": [
{
"field_value": "no",
"properties": {}
}
]
}
}
}
The PUT request now works. I did not pay attention to the value of the location header
in the response. The url for this endpoint has been changed to include the /
at the end.
So now, the PUT
https://www.commcarehq.org/a/mydomain/api/v0.5/lookup_table_item/7aed6de9b360458e8fd63365d2d61f3b/ works with the below payload, but the changes do not show in the HQ UI for Lookup Tables. I can confirm, via GET
, that the record was updated but not via the UI. Anything else to add? I used the below example payload for a successful PUT request:
{
"data_type_id": "59d698fea39144f197ba878dbd30rce6",
"fields": {
"survey": {
"field_list": [
{
"field_value": "strategy",
"properties": {}
}
]
},
"collect": {
"field_list": [
{
"field_value": "no",
"properties": {}
}
]
}
}
}
The UI
updates after about 10 mins
, not knowing what is going on behind the scenes, this might be helpful to note. Thanks.