The error message tag in body is required suggests that the Harbor API expects a different structure in the JSON body for tagging the artifact. Based on the Harbor API v2.0 documentation, the body should directly contain the name property instead of wrapping it inside a tag object.
Here’s how you can modify your curl command to make the request correctly:
The JSON body should be {"name": "0.0.1-snapshot"} instead of {"tag": {"name": "0.0.1-snapshot"}}.
Replace <username>, <password>, <mon_url_harbor>, <project_name>, <repository_name>, and <reference> with the appropriate values:
<username> and <password>: Your Harbor credentials.
<mon_url_harbor>: Your Harbor instance URL.
<project_name>: The name of the project in Harbor.
<repository_name>: The name of the repository in Harbor.
<reference>: The digest or tag of the artifact to which you want to add the new tag.
Example
If your project name is my-project, repository name is my-repo, artifact reference is sha256:abcd1234, and you want to add the tag 0.0.1-snapshot, the command will look like:
If successful, the API will return a 201 Created response, indicating the tag was added to the artifact successfully.
Additional Tips
Ensure the user you are authenticating with has sufficient permissions to create tags in the specified project.
Double-check that the artifact reference (e.g., digest or tag) exists in the specified repository.
If you continue to face issues, you can use the -v option in curl to see detailed logs of the request and response, which might provide more insights into the problem.