diff --git a/pkg/plugins/restapi/service.go b/pkg/plugins/restapi/service.go index f4e343d7..69031a03 100644 --- a/pkg/plugins/restapi/service.go +++ b/pkg/plugins/restapi/service.go @@ -194,9 +194,13 @@ func (r *RESTAPIConnector) Run(resourceOptions map[string]interface{}, actionOpt case METHOD_GET: resp, err := actionClient.SetQueryParams(actionURLParams).Get(baseURL + r.Action.URL) body := make(map[string]interface{}) + listBody := make([]map[string]interface{}, 0) if err := json.Unmarshal(resp.Body(), &body); err == nil { res.Rows = append(res.Rows, body) } + if err := json.Unmarshal(resp.Body(), &listBody); err == nil { + res.Rows = listBody + } res.Extra["raw"] = resp.Body() res.Extra["headers"] = resp.Header() if err != nil { @@ -207,9 +211,13 @@ func (r *RESTAPIConnector) Run(resourceOptions map[string]interface{}, actionOpt case METHOD_POST: resp, err := actionClient.SetQueryParams(actionURLParams).Post(baseURL + r.Action.URL) body := make(map[string]interface{}) + listBody := make([]map[string]interface{}, 0) if err := json.Unmarshal(resp.Body(), &body); err == nil { res.Rows = append(res.Rows, body) } + if err := json.Unmarshal(resp.Body(), &listBody); err == nil { + res.Rows = listBody + } res.Extra["raw"] = resp.Body() res.Extra["headers"] = resp.Header() if err != nil { @@ -220,9 +228,13 @@ func (r *RESTAPIConnector) Run(resourceOptions map[string]interface{}, actionOpt case METHOD_PUT: resp, err := actionClient.SetQueryParams(actionURLParams).Put(baseURL + r.Action.URL) body := make(map[string]interface{}) + listBody := make([]map[string]interface{}, 0) if err := json.Unmarshal(resp.Body(), &body); err == nil { res.Rows = append(res.Rows, body) } + if err := json.Unmarshal(resp.Body(), &listBody); err == nil { + res.Rows = listBody + } res.Extra["raw"] = resp.Body() res.Extra["headers"] = resp.Header() if err != nil { @@ -233,9 +245,13 @@ func (r *RESTAPIConnector) Run(resourceOptions map[string]interface{}, actionOpt case METHOD_PATCH: resp, err := actionClient.SetQueryParams(actionURLParams).Patch(baseURL + r.Action.URL) body := make(map[string]interface{}) + listBody := make([]map[string]interface{}, 0) if err := json.Unmarshal(resp.Body(), &body); err == nil { res.Rows = append(res.Rows, body) } + if err := json.Unmarshal(resp.Body(), &listBody); err == nil { + res.Rows = listBody + } res.Extra["raw"] = resp.Body() res.Extra["headers"] = resp.Header() if err != nil { @@ -246,9 +262,13 @@ func (r *RESTAPIConnector) Run(resourceOptions map[string]interface{}, actionOpt case METHOD_DELETE: resp, err := actionClient.SetQueryParams(actionURLParams).Delete(baseURL + r.Action.URL) body := make(map[string]interface{}) + listBody := make([]map[string]interface{}, 0) if err := json.Unmarshal(resp.Body(), &body); err == nil { res.Rows = append(res.Rows, body) } + if err := json.Unmarshal(resp.Body(), &listBody); err == nil { + res.Rows = listBody + } res.Extra["raw"] = resp.Body() res.Extra["headers"] = resp.Header() if err != nil {