Skip to content

REST API

Leonard Carcaramo edited this page Apr 15, 2021 · 1 revision

How to Use Artifactory's REST API Directly Using Curl

Ensure that you have access to an Artifactory service, and that you have access to a repository where you have read/write permission within that Artifactory service before you begin.

⚠️ It is highly recommended that you are always verifying Artifactory's CA Certificate. See the CA Certificates wiki if your Artifactory service uses an internal/self-signed SSL certificate to learn how to include the CA Certificate associated with your internal/self-signed SSL certificate in your HTTP/REST calls to Artifactory using curl to verify the certificate.

 

Upload Artifacts

Ensure that you have an artifact to upload to Artifactory, and that you have access to a repository where you have write permission in Artifactory.

Generate Checksums (Optional, but highly recommended.)

You do not have to generate checksums for your artifacts, but it is highly recommended that you do. Generating checksums for your artifacts before uploading them to Artifactory enables Artifactory to verify that the artifact that it receives is the same exact one that you uploaded. Matching checksums are an indication that both artifacts are identical. This is an additional layer of security that ensures that nothing happened to the artifact in transit. See the JFrog Checksums documentation for more details.

  • From a command prompt, ensure that you are in the directory where the artifact you want to upload to Artifactory lives.
  • Use a hash generation utility to generate a SHA1, SHA256, and MD5 checksum for the the artifact that you want to upload to Artifactory.

Perform Upload

  • Ensure that you are in the directory where the artifact that you want to upload to Artifactory lives.

  • Use the following template to upload an artifact WITHOUT checksums. ❌ (Not recommended)

$ curl -u <username>:<password> \
>      -T <name of file you want to upload> \
>      "http://<artifactory host/ip>/artifactory/<repository>/<desired artifact name>"
  • Use the following template to upload an artifact WITH checksums. ✔️ (recommended)
$ curl -u <username>:<password> \
>      -T <name of file you want to upload> \
>      -H "X-Checksum-Sha1:<SHA1 checksum for file you want to upload>" \
>      -H "X-Checksum-Sha256:<SHA256 checksum for file that you want to upload>" \
>      -H "X-Checksum-Md5:<MD5 checksum for file that you want to upload>" \
>      "http://<artifactory host/ip>/artifactory/<repository>/<desired artifact name>"

 

Download Artifacts

Ensure that you have an artifact in Artifactory to download, and that you at least have read permission for the repository where that artifact lives in before you begin.

Perform Download

  • Ensure that you are in the directory that you want to download the artifact from Artifactory to.
  • Use the following template to download the artifact:
$ curl -u <username>:<password> \
>      -O "http://<artifactory host/ip>/artifactory/<repository>/<artifact name>"

Get Metadata About The Artifact

This section explains how to get the metadata associated with an artifact stored in Artifactory. The main reason you might want to do this is because the artifact's checksums are included in this metadata. Therefore, you can generate checksums for the artifact after you download it, and then compare the checksums you generated to the ones included in the metadata to verify that nothing happened to the artifact in transit. Matching checksums indicate that the downloaded artifact is identical to the corresponding artifact that is stored in Artifactory.

  • Use the following template to get the metadata about the artifact that you just downloaded:
$ curl -u <username>:<password> \
>      -I "http://<artifactory host/ip>/artifactory/<repository>/<artifact name>"

 

Authentication Methods

This section explains how to use the two authentication methods that one can use to Authenticate with Artifactory using Artifactory's REST API directly.

Username/Password

  • Username/Password authentication is used in all of the previous examples using -u <username>:<password>.
$ curl -u <username>:<password> \
>      -T <name of file you want to upload> \
>      "http://<artifactory host/ip>/artifactory/<repository>/<desired artifact name>"

API Key

  • You may want to use API Key authentication instead of Username/Password authentication with Artifactory for a number of reasons (e.g. Increased security). You can authenticate with Artifactory using an API Key by removing the -u <username>:<password>, and replacing it with -H "X-JFrog-Art-Api:<your api key>". For more details on API Keys and how to generate them, see the API Keys wiki.
$ curl -H "X-JFrog-Art-Api:<your api key>" \
>      -T <name of file you want to upload> \
>      "http://<artifactory host/ip>/artifactory/<repository>/<desired artifact name>`