diff --git a/changes/45969-list-certificate-templates-null b/changes/45969-list-certificate-templates-null new file mode 100644 index 0000000000..993d2c7f7e --- /dev/null +++ b/changes/45969-list-certificate-templates-null @@ -0,0 +1 @@ +- Fixed `List certificate templates` API docs: query parameter was incorrectly documented as `fleet` instead of `fleet_id`, causing the parameter to be silently ignored and returning no results. diff --git a/docs/REST API/rest-api.md b/docs/REST API/rest-api.md index 8e9ba2fc9d..88d47dc3ae 100644 --- a/docs/REST API/rest-api.md +++ b/docs/REST API/rest-api.md @@ -936,7 +936,7 @@ List certificate added to Fleet. Currently, they can only be added via GitOps. | Name | Type | In | Description | | ----------| ------- | ---- | -------------------------------------------------------------- | -| fleet | string | query | _Available in Fleet Premium_. The fleet ID to filter profiles. | +| fleet_id | integer | query | _Available in Fleet Premium_. The fleet ID to filter certificate templates. | | page | integer | query | Page number of the results to fetch. | | per_page | integer | query | Results per page. | | order_key | string | query | What to order results by. Allowed field is `id`. | diff --git a/server/datastore/mysql/certificate_templates.go b/server/datastore/mysql/certificate_templates.go index 70db9d8ead..d803163b05 100644 --- a/server/datastore/mysql/certificate_templates.go +++ b/server/datastore/mysql/certificate_templates.go @@ -171,7 +171,7 @@ func (ds *Datastore) GetCertificateTemplatesByTeamID(ctx context.Context, teamID return nil, nil, ctxerr.Wrap(ctx, err, "apply list options") } - var templates []*fleet.CertificateTemplateResponseSummary + templates := []*fleet.CertificateTemplateResponseSummary{} if err := sqlx.SelectContext(ctx, ds.reader(ctx), &templates, stmtPaged, args...); err != nil { return nil, nil, ctxerr.Wrap(ctx, err, "getting certificate_templates by team_id") } diff --git a/server/datastore/mysql/certificate_templates_test.go b/server/datastore/mysql/certificate_templates_test.go index bf17a05201..bccd91f44d 100644 --- a/server/datastore/mysql/certificate_templates_test.go +++ b/server/datastore/mysql/certificate_templates_test.go @@ -488,6 +488,7 @@ func testGetCertificateTemplatesByTeamID(t *testing.T, ds *Datastore) { func(t *testing.T, ds *Datastore) { templates, _, err := ds.GetCertificateTemplatesByTeamID(ctx, 1, fleet.ListOptions{Page: 0, PerPage: 10}) require.NoError(t, err) + require.NotNil(t, templates, "expected empty slice, not nil (nil marshals to JSON null)") require.Len(t, templates, 0) }, },