Support for APIs that return a single object in an array
I'm trying to implement support for an API that returns (for some reason) an object in an array and restapi_object fails because of this:
[
{
"tags":["test","sandbox"],
"deployment":"ss2439879"
}
]
and my attempt:
resource "restapi_object" "tags" {
data = jsonencode({
tags = var.tags
})
create_path = "/deployment/${var.searchstax_deployment}/tags/"
read_path = "/deployment/${var.searchstax_deployment}/tags/"
destroy_path = "/deployment/${var.searchstax_deployment}/tags/"
object_id = "deployment"
id_attribute = "deployment"
path = "/deployment/${var.searchstax_deployment}/tags/"
}
fails because:
│ Error: json: cannot unmarshal array into Go value of type map[string]interface {}
The API is https://www.searchstax.com/docs/staxapi2tags/
Would it be possible to add a flag to support unwrapping the object from the array ? The API docs say: "The response is a list of JSON documents containing the deployment UID and the deployment’s current set of tags." but I don't see a reason for returning an array since the tags refer to a single deployment.
Something like: object_in_array = true or similar would help me here. For the same reason object_id and id_attribute fail because they cannot parse the object from the array. I've tried 0/deployment with no luck.
Hoping we can get support for something like this. Have the same issue with a few apis returning a single object in an array/list.
Similarly, my API returns the list of objects inside a top-level key { "data": [] }, so I'm looking for a way to map the response to what this plugin expects. Still investigating! I'm open to modifying the plugin if I have to, and so hope to find the most forward fork to contribute.