# Uploading from a CI

We provide a simple convenience script for ad hoc scan imports to DefectDojo. It can be downloaded from [here](https://raw.githubusercontent.com/MeterianHQ/django-DefectDojo/meterian-ci/api-sample-calls/ad-hoc-import.py).

### Prerequisites

* Python3
* the [requests](https://pypi.org/project/requests/) library&#x20;

#### Environment variables to export

The script uses required configurable environment variables matching information specific to the DefectDojo instance being used. Please ensure these are set correctly for error-free usage:

```
# DefectDojo API key found in the user settings
$ export DEFECTDOJO_API_TOKEN="352e9859215b35dd2xxx"

# Your installation-specific DefectDojo API base url 
$ export DEFECTDOJO_BASE_URL="https://my.defectdojo.xyz/"
```

### Usage

Assuming you have a working installation of DefectDojo on your system and Python3 installed, if you haven't already, create a **Product** on DefectDojo with the name matching exactly the name of the project that will be scanned with the Meterian client.

From the project folder, launch the Meterian scan and produce a JSON report (the following example uses [Meterian's dockerized client](https://docs.meterian.io/the-meterian-client-dockerized))

```
$ meterian-docker --report-json=/your/path/to/report.json
```

Then upload the findings to DefectDojo using our convenience script providing the path of the report to import as a parameter

```
$ python3 ad-hoc-import.py /your/path/to/report.json
```

If successful, the script will display a similar output

```
Uploading findings to Defect Dojo
Fetching for product matching project name: My First Product
Found product (ID: 3)
Created new AdHoc import engagement (ID: 24)
Imported findigs to test (ID: 22)
```

After successful execution, a new **Engagement** will be created on the fly and the results of the recent Meterian analysis will be imported as a Meterian Scan **Test** to it.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.meterian.io/management-platforms/defectdojo/ci-convenience-script-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
