# Components API

**URL:** <https://community.sonatype.com/t/components-api/14602>\
**Category:** Sonatype Nexus Repository\
**Created:** [March 13, 2025, 2:33pm UTC](https://community.sonatype.com/t/components-api/14602 "2025-03-13T14:33:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Curtis](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@John\_Curtis](https://community.sonatype.com/u/John_Curtis)\
**Post date:** [March 13, 2025, 2:33pm UTC](https://community.sonatype.com/t/components-api/14602/1 "2025-03-13T14:33:45Z")

</div>

I’m attempting to use the available API to post a tgz file to an existing repository. However, the resulting curl command:

```auto
curl -X 'POST' \
  'http://192.168.56.2/service/rest/v1/components?repository=node-local' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -H 'NX-ANTI-CSRF-TOKEN: 0.22859409376399165' \
  -H 'X-Nexus-UI: true' \
  -F 'npm.asset=@ansi-colors.tgz;type=application/x-compressed-tar'

```

yields the following error:

```auto
[
  {
    "id": "*",
    "message": "Name and version are mandatory fields"
  }
]

```

My question is how/where do I add the name and version values.  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [March 13, 2025, 2:46pm UTC](https://community.sonatype.com/t/components-api/14602/2 "2025-03-13T14:46:26Z")

</div>

If you haven’t already found the API document its available on the support document. Unfortunately there isn’t (wasn’t?) a good way to express sets of mandatory fields.

Probably you’d want to take a look at the Upload UI to get an idea about what is required for each format.

---

<div class="post-metadata">

**Author:** ![John\_Curtis](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@John\_Curtis](https://community.sonatype.com/u/John_Curtis)\
**Post date:** [March 13, 2025, 8:18pm UTC](https://community.sonatype.com/t/components-api/14602/3 "2025-03-13T20:18:46Z")

</div>

I appreciate the quick reply. Perhaps I missed it but I have not found anything on the Swaqger page or the Components API documentation that provides a list of mandatory fields. In this case there is just “repository” and “npm,asset” for the swagger page (same for the [Component API](https://help.sonatype.com/en/components-api.html)). Is there another resource that outlines that information? I have successfully used the process [outlined here](https://support.sonatype.com/hc/en-us/articles/115006744008-Repository-How-can-I-programmatically-upload-files-into-Nexus-3) to populate a maven repo.

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [March 13, 2025, 8:31pm UTC](https://community.sonatype.com/t/components-api/14602/4 "2025-03-13T20:31:11Z")

</div>

Right that was what I was getting at, the endpoint works across formats and Swagger doesn’t have a way to my knowledge to group parameters together.

This is why I suggest taking a look at the user interface for Upload, its backed by the same logic so if you should hopefully be able to mentally map fields in the UI to the API to understand which are mandatory (or if you know enough about the given format you may already know this).

---

<div class="post-metadata">

**Author:** ![John\_Curtis](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@John\_Curtis](https://community.sonatype.com/u/John_Curtis)\
**Post date:** [March 14, 2025, 1:43pm UTC](https://community.sonatype.com/t/components-api/14602/5 "2025-03-14T13:43:41Z")

</div>

Checking the UI’s Upload, it shows pretty much the same as Swagger, just the file (no name or version placeholders). However I think I may have it fixed as I discovered a bug I had in my tarball construction. Must be the API gets params from the tarball as the package.json was not at the appropriate level. Fixed my tarball issue and now no errors. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [March 14, 2025, 2:01pm UTC](https://community.sonatype.com/t/components-api/14602/6 "2025-03-14T14:01:26Z")

</div>

Yes, for npm packages embed metadata and the upload extracts that

---

<div class="post-metadata">

**Author:** ![slv\_b](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@slv\_b](https://community.sonatype.com/u/slv_b)\
**Post date:** [March 19, 2025, 9:17am UTC](https://community.sonatype.com/t/components-api/14602/7 "2025-03-19T09:17:29Z")

</div>

For row (hosted) there is more simple way to upload file.  
May this way can be good for you  
curl -u USERNAME:USERPASSWD --upload-file PathToYourFile [https://FQDN/repository/repoName/FolderInRepo/YourFile.tgz](https://FQDN/repository/repoName/FolderInRepo/YourFile.tgz)  
If you haven`t https - change to http.  
USERNAME - Nexus user  
USERPASSWD - Nexus user password  
PathToYourFile - path to file witch you want to upload

---

<div class="post-metadata">

**Author:** ![brian.veltman](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@brian.veltman](https://community.sonatype.com/u/brian.veltman)\
**Post date:** [March 27, 2025, 8:45am UTC](https://community.sonatype.com/t/components-api/14602/8 "2025-03-27T08:45:00Z")

</div>

If you’re using Ansible, I’m about to release a raw\_component module that enables you to upload files/components to raw repositories.

The Ansible task is currently looks like the following:

```yaml
- name: Upload artifact to Nexus
  cloudkrafter.nexus.raw_component:
    file: /tmp/package.tar.gz # file to be uploaded when state is present
    state: present # when absent, filename will be deleted from repository
    directory: /some-directory # Default is '/' for the root of the repository
    filename: package-name.tar.gz # name of component once uploaded
    repository: https://nexus.instance.local/repository/<repo_name>
    username: "{{ nexus_username }}"
    password: "{{ nexus_password }}" # use token or password
    usertoken: "{{ nexus_usertoken }}" # use token or password
    validate_certs: true

```

More modules are coming soon: [GitHub - CloudKrafter/nexus-ansible-collection: Ansible collection to install, configure and interact with Nexus Repository Manager](https://github.com/CloudKrafter/nexus-ansible-collection)
