ArgoCD API Patch Resource #9390
-
Hi, I'm trying to patch an application resource following the swagger documentation for the API. (https://cd.apps.argoproj.io/swagger-ui#operation/ApplicationService_PatchResource). But I'm getting error response. I have try different ways without luck. Request Info Query Params: Body: (JSON)
I have tried many different formats, including, passing the parameters in the request body.
Always getting this error response:
Is there a place where I can find more detailed information about the request format? Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I'm able to patch the resources using the CLI.
Result:
My API Call look like this:
Response:
I have tested different data formats like:
Any suggestion? |
Beta Was this translation helpful? Give feedback.
-
Problem solved! The issue was related with the query param I was using the following value |
Beta Was this translation helpful? Give feedback.
-
The solution mentioned did not work for me. I was doing raw HTTP POST requests similar to you. I found I was able to resolve the problem by migrating to making use of the ArgoCD client provided by the ArgoCD github repo. I believe the client is making gRPC calls rather than typical REST HTTP calls. Here is an example of how to create an ArgoCD client and invoke the PatchResource APi. package main
import (
"context"
"fmt"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"os"
)
func main() {
token := os.Getenv("ARGOCD_TOKEN")
argoCDURL := os.Getenv("ARGOCD_URL")
apiClient, err := apiclient.NewClient(&apiclient.ClientOptions{
ServerAddr: fmt.Sprintf(argoCDURL),
GRPCWeb: true,
AuthToken: token,
})
if err != nil {
panic(fmt.Errorf("failed to create argocd api client: %w", err))
}
_, appClient, err := apiClient.NewApplicationClient()
if err != nil {
panic(fmt.Errorf("failed to create argocd application client: %w", err))
}
_, err = appClient.PatchResource(context.TODO(), &application.ApplicationResourcePatchRequest{
// request data here
})
if err != nil {
panic(err)
}
} |
Beta Was this translation helpful? Give feedback.
Problem solved!
The issue was related with the query param
patchType
.I was using the following value
application/merge-patch+json
but it require the value in url encoded formatapplication%2Fmerge-patch%2Bjson