# Create a content attachment

From **GitHub v3 REST API**.

`POST /repos/{owner}/{repo}/content_references/{content_reference_id}/attachments`

Creates an attachment under a content reference URL in the body or comment of an issue or pull request. Use the `id` and `repository` `full_name` of the content reference from the [`content_reference` event](https://docs.github.com/enterprise-server@3.0/webhooks/event-payloads/#content_reference) to create an attachment.

The app must create a content attachment within six hours of the content reference URL being posted. See "[Using content attachments](https://docs.github.com/enterprise-server@3.0/apps/using-content-attachments/)" for details about content attachments.

You must use an [installation access token](https://docs.github.com/enterprise-server@3.0/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation) to access this endpoint.

## Parameters

### `owner`

- Location: path
- Required: true
- Type: `string`

The owner of the repository. Determined from the `repository` `full_name` of the `content_reference` event.

### `repo`

- Location: path
- Required: true
- Type: `string`

The name of the repository. Determined from the `repository` `full_name` of the `content_reference` event.

### `content_reference_id`

- Location: path
- Required: true
- Type: `integer`

The `id` of the `content_reference` event.

## Request body

- Required: true
### `application/json`

- Type: `object`

```json
{"properties":{"body":{"description":"The body of the attachment","example":"Body of the attachment","maxLength":262144,"type":"string"},"title":{"description":"The title of the attachment","example":"Title of the attachment","maxLength":1024,"type":"string"}},"required":["title","body"],"type":"object"}
```

## Responses

### `200`

Response

### `application/json`

- Type: `object`

Content Reference attachments allow you to provide context around URLs posted in comments

```json
{
  "body": "You have used an email that already exists for the user_email_uniq field.\n ## DETAILS:\n\nThe (email)=(Octocat@github.com) already exists.\n\n The error was found in core/models.py in get_or_create_user at line 62.\n\n self.save()",
  "id": 101,
  "title": "[A-1234] Error found in core/models.py file'"
}
```

```json
{"description":"Content Reference attachments allow you to provide context around URLs posted in comments","properties":{"body":{"description":"The body of the attachment","example":"Body of the attachment","maxLength":262144,"type":"string"},"id":{"description":"The ID of the attachment","example":21,"type":"integer"},"node_id":{"description":"The node_id of the content attachment","example":"MDE3OkNvbnRlbnRBdHRhY2htZW50MjE=","type":"string"},"title":{"description":"The title of the attachment","example":"Title of the attachment","maxLength":1024,"type":"string"}},"required":["id","title","body"],"title":"ContentReferenceAttachment","type":"object"}
```

### `304`

Not modified

### `403`

Forbidden

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `404`

Resource not found

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `410`

Gone

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `415`

Preview header missing

### `application/json`

- Type: `object`

```json
{"properties":{"documentation_url":{"type":"string"},"message":{"type":"string"}},"required":["message","documentation_url"],"type":"object"}
```

### `422`

Validation failed

### `application/json`

- Type: `object`

Validation Error

```json
{"description":"Validation Error","properties":{"documentation_url":{"type":"string"},"errors":{"items":{"properties":{"code":{"type":"string"},"field":{"type":"string"},"index":{"type":"integer"},"message":{"type":"string"},"resource":{"type":"string"},"value":{"oneOf":[{"nullable":true,"type":"string"},{"nullable":true,"type":"integer"},{"items":{"type":"string"},"nullable":true,"type":"array"}]}},"required":["code"],"type":"object"},"type":"array"},"message":{"type":"string"}},"required":["message","documentation_url"],"title":"Validation Error","type":"object"}
```

## Request examples

### cURL

```shell
curl --request POST \
  --url {protocol}://{hostname}/api/v3/repos/{owner}/{repo}/content_references/{content_reference_id}/attachments \
  --header 'content-type: application/json' \
  --data '{
  "body": "string",
  "title": "string"
}'
```
