---
id: user-grants-replace-all
title: Replace all grants for a user
description: >-
  Replace all existing grants for a user with a new set of grants. This
  operation **deletes all existing grants** and creates the new ones.
sidebar_label: Replace all grants for a user
hide_title: true
hide_table_of_contents: true
api: >-
  eJztWm1z27gR/is7+JJEpWUn5zQ9zlxnFNtJdM3FHlluruN4LIhYmTiTAAOAlnUa/ffOAqRESoqt9Npr2jl/kcSXfX322QXgORNoEyMLJ7ViMRtgkfEEgWcZ4L20TqobuDFcOQsTbYBDadHAVLoUOCicgkUHelI904VhKi3oAg0nidDpCMzQod0msdMBrgQkBjk94VL0ErVC2/2kPqk9OEclgJMYzAs3A24Mn3U6MLq8GoHTYDDXd8Ha2kijcy+J7OyuZECno7Taa4vxElYOVyK8cyTCFpjIiUSxMmmYYsM7aaHTcYYryxO6wLNOJwY5Aa5m3hUvESZcZhbueCaFfy8CpSFJubqhuBiEnAv04v+hS0i8v6VFQOlSNDAyOsNrKUag6x82K29GnY5PCfIkrRRJ5e02+LlE67qfFIuY4zeWxZdsoDP04faPsquILf3oCxYzilccIhBXQdnjWcYiZjEpjXQzFl/O2Ri5QdMrXcriy6vFVcQKbniODo31DyieI4uZFCxikiBVcJeyaA1nFMdSyc8lghSoHIXZeHeWuWMRI0ekQcFiZ0qMmE1SzDmL58zNCq9FObxBwxYRw3ueFxmy+NVfviezqiC81mJGLyRaOVSOvvKiyGTiPd//xZI5803JHiIbZvfo6gruBCDCf8vuJWgbWNuK1ZCfnN/3HeaWxc8PDiImw/c50wpPJz6iTjryi11YKh3KP1D+KbfBVj3+BRPXitclU4akL9FCCS8MpdxJ9ArogZW/1hmpbrbm6cPgA7kckGV1aRKEaYoGwyWyR1rg1sobhYLytswF0+aGK/mrD/YPz2OeJLpU7ocXlLGVbTuZQU8u7SClTldKfen8FT5ohzGcI8Ilgd1ePd0XOrH7vHSpNpUR+/SqfeZTlmuDINVEh0ysrBZ4hxnFii0Wi2hrBvrHu8dfim81+lJsKaZtVvSPf5/Qvzo4+O75q1cv/7xYLK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ngo/ZR8Qzmr81ZxtVN6RsSCyKJmHib19Z4LBzeb4vCfB6eGOpbVIvFMiiOflNcFot/AhgLYSY=
sidebar_class_name: put api-method
info_path: docs/api/authorization
custom_edit_url: null
canonical: 'https://docs.nullplatform.com/docs/api/user-grants-replace-all'
---
<Heading
  as={"h1"}
  className={"openapi__heading"}
  children={"Replace all grants for a user"}
>
</Heading>

<MethodEndpoint
  method={"put"}
  path={"/user/{id}/grant"}
  context={"endpoint"}
>

</MethodEndpoint>

Replace all existing grants for a user with a new set of grants. This operation **deletes all existing grants** and creates the new ones.

- Send an **empty array** `[]` to remove all grants from the user.
- Send a **non-empty array** to replace all grants with the specified ones.

The operation is **transactional**: if any new grant fails validation, no changes are made.

You can **use either `role_id` or `role_slug`** for each grant in the request.

<Heading
  id={"request"}
  as={"h2"}
  className={"openapi-tabs__heading"}
  children={"Request"}
>
</Heading>

<ParamsDetails
  parameters={[{"name":"id","in":"path","description":"The unique identifier for the user.","required":true,"schema":{"type":"integer"},"example":789}]}
>

</ParamsDetails>

<RequestSchema
  title={"Body"}
  body={{"content":{"application/json":{"schema":{"type":"array","description":"Array of grants to set for the user. Send an empty array to remove all grants.\n","maxItems":100,"items":{"oneOf":[{"title":"Using role slug","type":"object","required":["nrn","role_slug"],"properties":{"nrn":{"type":"string","description":"The NRN of the resource where the role is assigned.","example":"organization=1:account=2"},"role_slug":{"type":"string","description":"The slug of the role to assign.\n\n> Note: See [Roles](/docs/authorization/roles) for more info.\n","example":"developer"}}},{"title":"Using role ID","type":"object","required":["nrn","role_id"],"properties":{"nrn":{"type":"string","description":"The NRN of the resource where the role is assigned.","example":"organization=1:account=2"},"role_id":{"type":"integer","description":"The ID of the role to assign.\n\n> Note: See [Roles](/docs/authorization/roles) for more info.\n","example":700317756}}}]},"title":"bulkGrantReplaceRequest"},"examples":{"Replace with new grants":{"value":[{"nrn":"organization=1:account=2","role_slug":"admin"}]},"Remove all grants":{"value":[]}}}}}}
>

</RequestSchema>

<StatusCodes
  id={undefined}
  label={undefined}
  responses={{"200":{"description":"Grants were replaced successfully.","content":{"application/json":{"schema":{"type":"array","description":"Array of created/updated grants.","items":{"type":"object","required":["id","nrn","user_id","role_id","status"],"properties":{"id":{"type":"integer","description":"The unique identifier for the grant.","example":12345},"nrn":{"type":"string","description":"The NRN of the resource where the role is assigned.","example":"organization=1:account=2"},"user_id":{"type":"integer","description":"The ID of the user who received the grant.","example":789},"role_id":{"type":"integer","description":"The ID of the role assigned.","example":700317756},"role_slug":{"type":"string","description":"The slug of the role assigned.","example":"developer"},"status":{"type":"string","enum":["active","pending"],"description":"The status of the grant.","example":"active"}},"title":"bulkGrantResponse"},"title":"bulkGrantArrayResponse"}}}},"204":{"description":"All grants were removed (empty array was sent)."},"400":{"description":"The request failed validation. See POST endpoint for common causes.\n","content":{"application/json":{"schema":{"type":"object","required":["statusCode","code","error","message"],"properties":{"statusCode":{"type":"integer","description":"HTTP status code.","example":400},"code":{"type":"string","description":"Machine-readable error code.","example":"RESOURCE_GRANTS.BULK_CREATE_FAILED"},"error":{"type":"string","description":"Human-readable error type.","example":"Bad Request"},"message":{"type":"string","description":"Details about the error.","example":"Failed to create grants in bulk"},"cause":{"type":"object","description":"Details about the specific grant that failed.","properties":{"code":{"type":"string","description":"The specific error code for the failed grant.","example":"RESOURCE_GRANTS.DUPLICATE_GRANT"},"detail":{"type":"string","description":"Details about why this grant failed.","example":"The grant already exists"},"index":{"type":"integer","description":"The zero-based index of the grant that failed in the request array.","example":1}}}},"title":"bulkGrantError"}}}},"4XX":{"description":"The request couldn't be processed. For example, a parameter is invalid, the resource doesn't exist, or you don't have permission. The body is a problem details object (RFC 9457).","content":{"application/problem+json":{"schema":{"type":"object","description":"Describes what went wrong, following the RFC 9457 problem details format.","required":["type","title","status"],"properties":{"type":{"type":"string","description":"A URI that identifies the kind of problem. It's an identifier, not a link, and it's the same every time this problem occurs.","example":"urn:nullplatform:error:routes-helper:invalid-params"},"title":{"type":"string","description":"A short, human-readable summary of the problem.","example":"There are invalid parameters on the request"},"status":{"type":"integer","description":"The HTTP status code of the response.","example":400},"code":{"type":"string","description":"A stable, machine-readable error code. Use it to handle specific errors in your integrations.","example":"ROUTES_HELPER.INVALID_PARAMS"},"detail":{"type":"string","nullable":true,"description":"More information about what went wrong in this request, when available.","example":null},"errors":{"type":"array","description":"One entry per invalid field or parameter. Only present on validation errors.","items":{"type":"object","properties":{"field":{"type":"string","description":"The name of the invalid field or parameter.","example":"application_id"},"in":{"type":"string","description":"Where the field was sent: `body`, `query`, or `params` (path parameters).","example":"query"},"issue":{"type":"string","description":"What's wrong with the field, such as `required` or `invalid`.","example":"invalid"},"value":{"description":"The value that was sent, when relevant.","example":"not-a-number"},"message":{"type":"string","description":"A human-readable explanation of the issue."}}}},"message":{"type":"string","deprecated":true,"description":"Same value as `title`, kept for backward compatibility. Use `title` or `code` instead.","example":"There are invalid parameters on the request"},"traceId":{"type":"string","description":"An identifier for this request, when available. Include it when you contact nullplatform support."}}}}}},"5XX":{"description":"Something went wrong on nullplatform's side. The body is a problem details object (RFC 9457).","content":{"application/problem+json":{"schema":{"type":"object","description":"Describes what went wrong, following the RFC 9457 problem details format.","required":["type","title","status"],"properties":{"type":{"type":"string","description":"A URI that identifies the kind of problem. It's an identifier, not a link, and it's the same every time this problem occurs.","example":"about:blank"},"title":{"type":"string","description":"A short, human-readable summary of the problem.","example":"Oops.. there was an internal error"},"status":{"type":"integer","description":"The HTTP status code of the response.","example":500},"code":{"type":"string","description":"A stable, machine-readable error code. Use it to handle specific errors in your integrations."},"detail":{"type":"string","nullable":true,"description":"More information about what went wrong in this request, when available.","example":null},"message":{"type":"string","deprecated":true,"description":"Same value as `title`, kept for backward compatibility. Use `title` or `code` instead.","example":"Oops.. there was an internal error"},"traceId":{"type":"string","description":"An identifier for this request, when available. Include it when you contact nullplatform support."}}}}}}}}
>

</StatusCodes>

