# Connect a GitHub repository to a project

POST

/organizations/{organizationId}/projects/{projectId}/repositories

```js
const url = 'https://zkao.io/api/v1/organizations/example/projects/example/repositories';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"owner":"example","name":"example"}'
};


try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```sh
curl --request POST \
  --url https://zkao.io/api/v1/organizations/example/projects/example/repositories \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{ "owner": "example", "name": "example" }'
```

* Production`zkao.io/api/v1/organizations/{organizationId}/projects/{projectId}/repositories`
* Staging`staging.zkao.io/api/v1/organizations/{organizationId}/projects/{projectId}/repositories`

Requires an organization token with scope `repositories:write`. The same checks as the dashboard apply. A private repository needs the zkao GitHub App installed for it, and the member who created the token must have access to it on GitHub with a verified GitHub account. A new repository is `analyzing` until its first pass finishes.

## Authorizations

* **[bearerAuth](https://docs.staging.zkao.io/api/#bearerauth)**

## Parameters

### Path Parameters

* **organizationId**

  required

  string

  The organization’s id, as `GET /token` reports it.

* **projectId**

  required

  string

## Request Bodyrequired

application/json

object

* **owner**

  required

  GitHub user or organization.

  string

* **name**

  required

  Repository name.

  string

##### Examplegenerated

```json
{
  "owner": "example",
  "name": "example"
}
```

## Responses

### 201

Created

application/json

object

* **repository**

  required

  object

  * **id**

    required

    string

  * **slug**

    required

    URL segment of the repository inside its project (`/orgs/<org>/projects/<project>/repos/<slug>`). Unique per project.

    string

  * **owner**

    required

    string

  * **name**

    required

    string

  * **url**

    required

    string

  * **defaultBranch**

    string | null

  * **status**

    required

    ACTIVE | MARKED_FOR_DELETION

    string

  * **readiness**

    required

    Whether a scan can start on this repository. A newly added repository is `analyzing` until a one-time pass over it finishes; launching a scan meanwhile fails with `repository_initializing`. Poll this endpoint rather than retrying the launch blind.

    string

    Allowed values: ready analyzing

##### Example

```json
{
  "repository": {
    "readiness": "ready"
  }
}
```

### 400

Invalid request

application/json

object

* **error**

  required

  object

  * **code**

    required

    string

    Allowed values: unauthorized forbidden not_found bad_request conflict insufficient_credits budget_below_minimum repository_initializing diff_base_required diff_base_not_allowed diff_base_invalid diff_empty rate_limited internal

  * **message**

    required

    string

  * **minimumCredits**

    Budget_below_minimum only: the least the launch could have reserved, in credits. A diff scan’s first scan of a repository also builds its overview, so its minimum is higher.

    integer

##### Example

```json
{
  "error": {
    "code": "unauthorized"
  }
}
```

### 401

Missing, malformed, expired, or revoked token

application/json

object

* **error**

  required

  object

  * **code**

    required

    string

    Allowed values: unauthorized forbidden not_found bad_request conflict insufficient_credits budget_below_minimum repository_initializing diff_base_required diff_base_not_allowed diff_base_invalid diff_empty rate_limited internal

  * **message**

    required

    string

  * **minimumCredits**

    Budget_below_minimum only: the least the launch could have reserved, in credits. A diff scan’s first scan of a repository also builds its overview, so its minimum is higher.

    integer

##### Example

```json
{
  "error": {
    "code": "unauthorized"
  }
}
```

### 403

The token is a project token, or lacks the required scope

application/json

object

* **error**

  required

  object

  * **code**

    required

    string

    Allowed values: unauthorized forbidden not_found bad_request conflict insufficient_credits budget_below_minimum repository_initializing diff_base_required diff_base_not_allowed diff_base_invalid diff_empty rate_limited internal

  * **message**

    required

    string

  * **minimumCredits**

    Budget_below_minimum only: the least the launch could have reserved, in credits. A diff scan’s first scan of a repository also builds its overview, so its minimum is higher.

    integer

##### Example

```json
{
  "error": {
    "code": "unauthorized"
  }
}
```

### 404

Resource not in this token’s project or repo allowlist

application/json

object

* **error**

  required

  object

  * **code**

    required

    string

    Allowed values: unauthorized forbidden not_found bad_request conflict insufficient_credits budget_below_minimum repository_initializing diff_base_required diff_base_not_allowed diff_base_invalid diff_empty rate_limited internal

  * **message**

    required

    string

  * **minimumCredits**

    Budget_below_minimum only: the least the launch could have reserved, in credits. A diff scan’s first scan of a repository also builds its overview, so its minimum is higher.

    integer

##### Example

```json
{
  "error": {
    "code": "unauthorized"
  }
}
```

### 409

The repository is already in the project (code `conflict`)

application/json

object

* **error**

  required

  object

  * **code**

    required

    string

    Allowed values: unauthorized forbidden not_found bad_request conflict insufficient_credits budget_below_minimum repository_initializing diff_base_required diff_base_not_allowed diff_base_invalid diff_empty rate_limited internal

  * **message**

    required

    string

  * **minimumCredits**

    Budget_below_minimum only: the least the launch could have reserved, in credits. A diff scan’s first scan of a repository also builds its overview, so its minimum is higher.

    integer

##### Example

```json
{
  "error": {
    "code": "unauthorized"
  }
}
```

### 429

Rate limited. Either the token’s spend limit for the current period is reached (on launch), or the token is sending too many requests. Wait the number of seconds in the `Retry-After` header before retrying.

application/json

object

* **error**

  required

  object

  * **code**

    required

    string

    Allowed values: unauthorized forbidden not_found bad_request conflict insufficient_credits budget_below_minimum repository_initializing diff_base_required diff_base_not_allowed diff_base_invalid diff_empty rate_limited internal

  * **message**

    required

    string

  * **minimumCredits**

    Budget_below_minimum only: the least the launch could have reserved, in credits. A diff scan’s first scan of a repository also builds its overview, so its minimum is higher.

    integer

##### Example

```json
{
  "error": {
    "code": "unauthorized"
  }
}
```

#### Headers

* **Retry-After**

  integer

  Seconds to wait before retrying.
