How to upload a pcap file with a REST API Key

Uploading a pcap File Using a REST API Key: A Guide for Professional and Advanced Plan Subscribers.

If you're a subscriber to our Professional or Advanced plan, you have the exclusive capability to upload pcap files through our REST API Key. Here's a step-by-step breakdown of the process:

  1. Subscription Requirement : This feature is accessible only to customers who have opted for the Professional or Advanced plan.
  2. Locating Your REST API Key: To begin, log in to your account and navigate to your profile. If you have a Professional subscription or higher, you'll find your REST API Key here. You have the option to either reveal your existing key by clicking "Show," or you can choose to generate a new one by clicking "Generate" if needed.
  3. Key Functionality: The REST API Key is pivotal for enabling this feature. It not only authenticates your access but also carries over the features and limitations of your account. This means that any constraints you've set, such as limiting the number of files or the file sizes, will also be applicable when utilizing the key for file uploads.

Remember, the ability to upload pcap files via the REST API Key provides a streamlined and efficient way for Professional and Advanced plan subscribers to manage and utilize their account features.

REST API key in user profile
REST API key in user profile

Upload a pcap file

An upload takes three requests: open it with the file's name, size and MD5, send the file to the storage link the answer contains, then start the analysis. The file goes straight to storage, and the link accepts only that file: the size and MD5 you declared are signed into it. The example uses jq to read the answers.

FILE="capture.pcapng"
KEY="<REST API Key>"
MD5=$(md5sum "$FILE" | cut -d' ' -f1)   # macOS: MD5=$(md5 -q "$FILE")
SIZE=$(wc -c < "$FILE" | tr -d ' ')

INIT=$(curl -sS -X POST https://apackets.com/api/v1/pcaps/private/uploads \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d "{\"name\":\"$(basename "$FILE")\",\"size\":$SIZE,\"md5\":\"$MD5\"}")

curl -sS -T "$FILE" "$(echo "$INIT" | jq -r .upload.url)" \
  -H "Content-Type: application/vnd.tcpdump.pcap" \
  -H "Content-MD5: $(echo "$INIT" | jq -r '.upload.headers["Content-MD5"]')"

curl -sS -X POST -H "Authorization: Bearer $KEY" \
  "https://apackets.com/api/v1/pcaps/private/uploads/$(echo "$INIT" | jq -r .upload_id)/complete"

The first request answers with the upload link, which works for 15 minutes:

{"upload_id":"<upload id>","uuid":"<pcap UUID>","name":"<pcap file name>","upload":{"method":"PUT","url":"<storage link>","headers":{"Content-Type":"application/vnd.tcpdump.pcap","Content-MD5":"<MD5 in base64>"},"expires_at":"<time>"}}

If you have uploaded this file before, it answers 202 with "exists": true and the pcap UUID instead; skip the other two requests. The last request answers 202 with the pcap UUID, a unique identifier for future referencing:

{"uuid":"<pcap UUID>","name":"<pcap file name>"}

Processing status

While the file is undergoing processing, you can monitor its status by utilizing the pcap UUID obtained in the previous step.

curl -H "Authorization: Bearer <REST API Key>" "https://apackets.com/api/v1/pcaps/private/status/<pcap UUID>"

Once the pcap processing has concluded, the request will furnish a response.

{"status": "ok"}
otherwise
{"status": "processing"}

Once the processing is finalized, you can conveniently navigate to and oversee the managed files in your profile through the following link: https://apackets.com/my

Usage info

To assess your subscription limits and review your current usage, execute the following command:

curl -H "Authorization: Bearer <REST API Key>" https://apackets.com/api/v1/pcaps/private/user/limits

Here's an exemplar of the output:

{
  "currentFilesCount": 2,
  "filesLimit": 500,
  "maxFileSize": 104857600
}

Worked examples on real captures

The use cases work analyst tasks through public sample captures, and the sample reports analyze one capture each, in full, next to its interactive report.

All use cases All sample reports