Documentation Index

Fetch the complete documentation index at: https://help.nucleussec.com/llms.txt

Use this file to discover all available pages before exploring further.

Uploading a file to Nucleus via API using Python3 Requests Library

Prev Next

Overview

Nucleus makes it easy to post data to it and ingest the results from custom data types. One popular way of scripting out data to be sent to Nucleus is using the Python Requests Library. This article shows you how easy it is to post data to Nucleus with Python. It assumes you have Python 3 installed as well as the requests library.

Install Python and the requests library

Example, on Ubuntu, to install python and the requests library:

sudo apt-get install python3
pip install --upgrade-pip
pip install requests

Once you have Python set up, you can post data to Nucleus via the API in the following way:

  1. First you need to make sure you have a file to upload. You can use any of our natively supported scan types or you can format the data according to our custom data type as described here.

  2. Copy and paste the following code into a python file:

import requests

Set up API key
apikey = '{enter api key here}'

# Set Up Nucleus URL
# Example nucleus url: https://example.com/nucleus/api/projects/{enter project id here}/scans
NUCLEUS_URL = '{enter Nucleus url here}'

with open('{choose file to upload here}', 'rb') as f:

# Send file with proper headers (only need api key)
# Take note of the project id you wish to send the file to
file_upload_endpoint = requests.post(NUCLEUS_URL, files={'{choose file to upload here}': f}, headers={'x-apikey':apikey})

    print(file_upload.content)
  1. Edit the python file with the following criteria:
Criteria Info
API Key Log into your Nucleus console and navigate to your user profile. Copy the API key from this screen and enter it in the brackets of the above script.
Choose File to Upload Both of these should be the same file. This is the file you are posting to Nucleus.
URL Make sure that the url you are posting to is the url of the Nucleus instance on which you are hosted.
Project ID Verify the project ID of the project to which you are posting, which needs to be included in the URL.

This basic script will take a file from your local directory and post it to your Nucleus instance.

If you have any questions, please contact us through the support center.