> For the complete documentation index, see [llms.txt](https://docs.xygeni.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xygeni.io/xygeni-products/application-security-posture-management-aspm/inventory-scanner/inventory-api-scan.md).

# Inventory API Scan

The Inventory Scan can discover the API surface of the project and add it to the inventory as assets:

* **API services**, one per API the project exposes.
* **API modules**, the REST resources or controllers of each service.
* **API endpoints**, one per operation (HTTP method and path).

Each service is linked to the repository it belongs to, and each endpoint to its module and service.

API discovery parses the source code and the OpenAPI specifications of the project. It is the same discovery the [API Security Scanner](https://docs.xygeni.io/xygeni-products/api-security/api-security-scanner.md) runs. Because parsing the source code takes time, API discovery is **off by default** and is enabled with the `--api-inventory` option.

### How to run an API inventory scan <a href="#how_to_run_api_inventory_scan" id="how_to_run_api_inventory_scan"></a>

Example:

```shell
xygeni inventory --dir DIR --upload --api-inventory
```

When the inventory scan runs inside a full `xygeni scan` that also runs API Security, the API is discovered only once and shared by both scanners.

### What happens to the API inventory on each scan <a href="#api_inventory_on_each_scan" id="api_inventory_on_each_scan"></a>

Every inventory scan uploaded to Xygeni replaces the inventory of the branch it was run on. For the API assets, the result depends on whether the scan ran API discovery:

| Inventory scan                                   | API assets of the branch                                                                                                                                                                                                |
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **With** `--api-inventory`                       | Replaced by the APIs the scan discovered. If the scan finds no API, the branch is left with no API assets.                                                                                                              |
| **Without** `--api-inventory`                    | **Kept** from the branch's previous inventory, together with their links to the repository and to the other assets that still exist, and with their origin (see below). The rest of the inventory is replaced as usual. |
| With `--api-inventory`, but API discovery failed | **Kept**, as if the option had not been used. The scan log shows a warning.                                                                                                                                             |

So a pipeline does not need to run `--api-inventory` on every scan to keep its API inventory. Run it when you want the API inventory refreshed, for example on a schedule or on the main branch, and run faster inventory scans without it in between.

{% hint style="info" %}
API assets are only kept within the same project and branch. A scan without `--api-inventory` on a branch that has never had API assets results in an inventory with no API assets.
{% endhint %}

### API inventory from API Security reports <a href="#api_inventory_from_api_security" id="api_inventory_from_api_security"></a>

With the SDLC Inventory feature in your license, an [API Security](https://docs.xygeni.io/xygeni-products/api-security.md) scan also adds the APIs it discovers to the inventory of the branch.

Xygeni records where the API assets of the branch came from: an **inventory scan** with `--api-inventory`, or an **API Security** report. An inventory scan without `--api-inventory` keeps them together with that origin, so it does not change who they belong to. What an API Security report does depends on that origin:

| API assets of the branch                                                                                     | API Security report with APIs                                                                       | API Security report with no API |
| ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- | ------------------------------- |
| None                                                                                                         | **Adds** them to the branch's latest inventory. If the branch has no inventory yet, it creates one. | Nothing to do.                  |
| Discovered by an inventory scan with `--api-inventory`, also when later scans without it kept them           | **Does not change them.** The inventory scan takes precedence.                                      | **Does not change them.**       |
| Added by an earlier API Security report, also when later inventory scans without `--api-inventory` kept them | **Replaces** them with the APIs it discovered.                                                      | **Removes** them.               |

The same rules apply when the inventory and API Security run in the same `xygeni scan`.

{% hint style="info" %}
Running the inventory with `--api-inventory` and API Security in the same `xygeni scan` keeps both views of the API consistent.

Once an inventory scan with `--api-inventory` has discovered the APIs of a branch, API Security reports no longer update them. To refresh them, run the inventory scan with `--api-inventory` again.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.xygeni.io/xygeni-products/application-security-posture-management-aspm/inventory-scanner/inventory-api-scan.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
