# Creating and importing projects

## Overview <a href="#overview" id="overview"></a>

There are several ways to create a project in SonarQube:

* **Import from DevOps Platforms** (Enterprise edition and above): If your project is bound to a DevOps platform and you want to benefit from the integration features out of the box (pull request decoration, code scanning alerts, permission synchronization, etc.), go to **Create Project** > **Import from DevOps Platforms** from the homepage.

  If you already have a DevOps platform Integration configured, you’ll be able to directly use it. For example, by clicking **Create Project** > **From GitHub**.
* **Local project**: For a project not linked to a DevOps platform, you can use **Create** > **Local** on the Projects page.
* **Automate through the API**: Both methods mentioned above can be automated using the Web API.
* **First scan**: If none of the above is relevant, you can create a project by scanning it for the first time.

All the above methods require the **Create Projects** permission, which can be configured in **Administration** > **Security** > **Global Permissions.**

## Choosing a method for project creation <a href="#choosing-a-method-for-project-creation" id="choosing-a-method-for-project-creation"></a>

When a project is created in SonarQube through a first scan, the default configuration applies: default quality profile for each language, default quality gate, default visibility, a permissions template is applied if applicable, etc.

While this is handy, this method is not always desirable as it doesn’t allow a proper configuration upfront. If you want to configure your project before you run a first analysis, use one of the following options:

* **Import from DevOps Platforms**: If your project is hosted on GitHub, GitLab, Azure DevOps, or BitBucket
* **Local project:** If your project is not hosted on a DevOps platform (in rare cases).

## Automating project creation and import <a href="#automating-project-creation-and-import" id="automating-project-creation-and-import"></a>

When you have a large project base, it can be interesting to automate project creation and import using the Web API. If you’re getting started with Web API, check out the [web-api](https://docs.sonarsource.com/sonarqube-server/10.7/extension-guide/web-api "mention") page.

### Automate local project creation <a href="#automate-local-project-creation" id="automate-local-project-creation"></a>

Only using the Web API `/api/projects/create` is enough to create a local project. A name and a project key are the only necessary parameters.

### Automate the import of projects hosted on a DevOps platform <a href="#automate-the-import-of-projects-hosted-on-a-devops-platform" id="automate-the-import-of-projects-hosted-on-a-devops-platform"></a>

To provision a project from a DevOps platform, SonarQube needs to communicate with the said platform using a personal access token.

This is done in two steps. First, get the personal access token using the `POST api/alm_integrations/set_pat`

endpoint, then use the `POST api/alm_integrations/import_<yourdevopsplatform>_project` to set up the automation.

1. You’ll first need to use the `POST api/alm_integrations/set_pat` endpoint to provide this token. Specify the following parameters:
   * `pat`: The personal access token itself.
   * `almSetting`: Optional. The DevOps Platform configuration name that you target. This can be hardcoded in your automation, or you can use `GET api/alm_settings/list` to have the full list. If you have only one Devops platform configuration in your instance, you can skip this parameter.
   * `username`: Optional. Only for BitBucket Cloud, as the actual authentication token is the combination of the username and the personal access token.

2\. Once you’ve provided the token, use the following [import endpoint](https://next.sonarqube.com/sonarqube/web_api_v2#/dop-translation/bound-projects--post) to set up the automation:

* `POST api/v2/dop-translation/bound-projects`

The details of how to use these endpoints are documented in the [Web API v2.0 documentation](https://next.sonarqube.com/sonarqube/web_api_v2).
