growthbook
growthbook copied to clipboard
Add batch metric delete API
Features and Changes
addresses #2630
Adds a DELETE
resource on /api/v1/metrics
that takes a json body w/ a list of metrics and a query parameter (delete
) to either archive or for-real-delete multiple metrics at once.
I'm still a little unfamiliar with zod but I think this usage of preprocess
gets what we want? It might be better to just make the query parameter a string type (instead of boolean) and only strictly accept true
and false
.
It might also make more sense to move the archiving functionality to a batch metric PUT api, but re-using DELETE
for archiving seemed somewhat intuitive
Testing
Breaks when using query parameter other than delete
:
curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky4ef", "met_6y4depgjpklzbvdhdo"]}' localhost:3100/api/v1/metrics\?deleted=true
{
"message": "Querystring: [] Unrecognized key(s) in object: 'deleted'"
}
archive one or more metrics with delete=false
:
curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky3ad"]}' localhost:3100/api/v1/metrics\?delete=false
{
"modifiedIds": [
"met_6y4deo1kzblyxky3ad"
],
"deleted": false
}
curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky44p", "met_6y4deo1kzblyxky2jw"]}' localhost:3100/api/v1/metrics\?delete=false
{
"modifiedIds": [
"met_6y4deo1kzblyxky44p",
"met_6y4deo1kzblyxky2jw"
],
"deleted": false
}
delete multiple metrics with delete=true
:
> curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky4ef", "met_6y4depgjpklzbvdhdo"]}' localhost:3100/api/v1/metrics\?delete=true
{
"modifiedIds": [
"met_6y4deo1kzblyxky4ef",
"met_6y4depgjpklzbvdhdo"
],
"deleted": true
}
must provide delete param of true/false
:
> curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky5hj"]}' localhost:3100/api/v1/metrics\?delete=something
{
"message": "Querystring: [delete] Expected boolean, received string"
}
> curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky5hj"]}' localhost:3100/api/v1/metrics\?delete
{
"message": "Querystring: [delete] Expected boolean, received string"
}
> curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky5hj"]}' localhost:3100/api/v1/metrics\?delete=f
{
"message": "Querystring: [delete] Expected boolean, received string"
}
> curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky5hj"]}' localhost:3100/api/v1/metrics\?delete=0
{
"message": "Querystring: [delete] Expected boolean, received string"
}
> curl -H "Content-Type: application/json" -H "Authorization: Bearer ..." -X DELETE --data '{"ids": ["met_6y4deo1kzblyxky5hj"]}' localhost:3100/api/v1/metrics\?delete=1
{
"message": "Querystring: [delete] Expected boolean, received string"
}