Sample - GitHub REST API
POST/orgs/{org}/rulesets

Create an organization repository ruleset

Creates a repository ruleset for an organization. Supply name and enforcement, and use target, bypass_actors, conditions, and rules to define where and how the ruleset applies. A 201 response returns the created organization repository ruleset with its identifier, source, conditions, rules, and timestamps.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

1 parameter · 6 body fields
orgstringrequired
The organization name. Matching is not case-sensitive.

Organization repository ruleset definition. name and enforcement are required.

namestringrequired
The name of the ruleset.
targetstringoptional
The target of the ruleset
Allowed:branchtagpushrepositoryDefault:branch
enforcementstringrequired
The enforcement level of the ruleset. `evaluate` allows admins to test rules before enforcing them. Admins can view insights on the Rule Insights page (`evaluate` is only available with GitHub Enterprise).
Allowed:disabledactiveevaluate
bypass_actorsarray<RepositoryRulesetBypassActor>optional
The actors that can bypass the rules in this ruleset
conditionsobjectoptional
Conditions for an organization ruleset. The branch and tag rulesets conditions object should contain both `repository_name` and `ref_name` properties, or both `repository_id` and `ref_name` properties, or both `repository_property` and `ref_name` properties. The push rulesets conditions object does not require the `ref_name` property. For repository policy rulesets, the conditions object should only contain the `repository_name`, the `repository_id`, or the `repository_property`.
rulesarray<RepositoryRule>optional
An array of rules within the ruleset.

4 status codes
201Returns the created organization repository ruleset, including its identifier, name, source, enforcement level, bypass actors, conditions, rules, and timestamps.
idintegerrequired
The ID of the ruleset
namestringrequired
The name of the ruleset
targetstringoptional
The target of the ruleset
Allowed:branchtagpushrepository
source_typestringoptional
The type of the source of the ruleset
Allowed:RepositoryOrganizationEnterprise
sourcestringrequired
The name of the source
enforcementstringrequired
The enforcement level of the ruleset. `evaluate` allows admins to test rules before enforcing them. Admins can view insights on the Rule Insights page (`evaluate` is only available with GitHub Enterprise).
Allowed:disabledactiveevaluate
bypass_actorsarray<RepositoryRulesetBypassActor>optional
The actors that can bypass the rules in this ruleset
current_user_can_bypassstringoptional
The bypass type of the user making the API request for this ruleset. This field is only returned when querying the repository-level endpoint.
Allowed:alwayspull_requests_onlyneverexempt
node_idstringoptional
_linksobjectoptional
conditionsobjectoptional
Parameters for a repository ruleset ref name condition
rulesarray<RepositoryRule>optional
created_atstringoptional
updated_atstringoptional
404Returned when the organization or another referenced resource cannot be found.
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
422Returned when validation fails or the endpoint has been spammed, including when required fields are missing or values are invalid.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional
500Returned when an internal error occurs.
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional

Error handling

A 404 is returned when the specified organization or related resource cannot be found. A 422 is returned when name or enforcement is missing, a value violates the schema, or the endpoint has been spammed. A 500 indicates an internal error; enforcement must be one of disabled, active, or evaluate, and target must be one of branch, tag, push, or repository.