# Create a pre-receive hook

From **GitHub v3 REST API**.

`POST /admin/pre-receive-hooks`

Create a pre-receive hook

## Request body

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

- Type: `object`

```json
{
  "allow_downstream_configuration": false,
  "enforcement": "disabled",
  "environment": {
    "id": 2
  },
  "name": "Check Commits",
  "script": "scripts/commit_check.sh",
  "script_repository": {
    "full_name": "DevIT/hooks"
  }
}
```

```json
{"properties":{"allow_downstream_configuration":{"description":"Whether enforcement can be overridden at the org or repo level. default: `false`","type":"boolean"},"enforcement":{"description":"The state of enforcement for this hook. default: `disabled`","type":"string"},"environment":{"additionalProperties":true,"description":"The pre-receive environment where the script is executed.","type":"object"},"name":{"description":"The name of the hook.","type":"string"},"script":{"description":"The script that the hook runs.","type":"string"},"script_repository":{"additionalProperties":true,"description":"The GitHub repository where the script is kept.","type":"object"}},"required":["name","script","script_repository","environment"],"type":"object"}
```

## Responses

### `201`

Response

### `application/json`

- Type: `object`

```json
{
  "allow_downstream_configuration": false,
  "enforcement": "disabled",
  "environment": {
    "created_at": "2016-05-20T11:35:45-05:00",
    "default_environment": false,
    "download": {
      "downloaded_at": "2016-05-26T07:42:53-05:00",
      "message": null,
      "state": "success",
      "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest"
    },
    "hooks_count": 1,
    "html_url": "https://github.example.com/admin/pre-receive-environments/2",
    "id": 2,
    "image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
    "name": "DevTools Hook Env",
    "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2"
  },
  "id": 1,
  "name": "Check Commits",
  "script": "scripts/commmit_check.sh",
  "script_repository": {
    "full_name": "DevIT/hooks",
    "html_url": "https://github.example.com/DevIT/hooks",
    "id": 595,
    "url": "https://github.example.com/api/v3/repos/DevIT/hooks"
  }
}
```

```json
{"properties":{"allow_downstream_configuration":{"type":"boolean"},"enforcement":{"type":"string"},"environment":{"properties":{"created_at":{"type":"string"},"default_environment":{"type":"boolean"},"download":{"properties":{"downloaded_at":{"nullable":true,"type":"string"},"message":{"nullable":true,"type":"string"},"state":{"type":"string"},"url":{"type":"string"}},"type":"object"},"hooks_count":{"type":"integer"},"html_url":{"type":"string"},"id":{"type":"integer"},"image_url":{"type":"string"},"name":{"type":"string"},"url":{"type":"string"}},"type":"object"},"id":{"type":"integer"},"name":{"type":"string"},"script":{"type":"string"},"script_repository":{"properties":{"full_name":{"type":"string"},"html_url":{"type":"string"},"id":{"type":"integer"},"url":{"type":"string"}},"type":"object"}},"type":"object"}
```

## Request examples

### cURL

```shell
curl --request POST \
  --url {protocol}://{hostname}/api/v3/admin/pre-receive-hooks \
  --header 'content-type: application/json' \
  --data '{
  "allow_downstream_configuration": false,
  "enforcement": "disabled",
  "environment": {
    "id": 2
  },
  "name": "Check Commits",
  "script": "scripts/commit_check.sh",
  "script_repository": {
    "full_name": "DevIT/hooks"
  }
}'
```
