Updating and Deleting Client Grant

Learn how to update and delete a client grant using Auth0 API.

In this lesson, we'll see how we can update a client grant on a client application and delete a client grant of an application using an API call. We'll use the https://{{DOMAIN}}/api/v2/client-grant endpoint to achieve these tasks. Creating a client grant is a PATCH request, while deleting a client grant is a DELETE request.

Press + to interact
Updating a client grant and deleting a client grant endpoint
Updating a client grant and deleting a client grant endpoint

Updating a client grant

We may need to update the client grant from time to time if the requirements change. In that scenario, Auth0 provides a client-grants endpoint that allows us to update the client grant.

Request parameters

Since we are updating a grant here, please provide the request parameters. The different options for a scope can be given here.

We’ll use *, which updates all scopes.

Click the “Run” button to execute the code in the code widget below:

Press + to interact
// Importing libraries here
const fetch = require('node-fetch');
const endpointUrl = new URL('https://{{DOMAIN}}/api/v2/client-grants/{{CLIENT_GRANT_ID}}');
const headerParameters = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{ACCESS_TOKEN}}',
}
const bodyParameters = JSON.stringify({
"scope": [
"*"
]
});
const options = {
method: 'PATCH',
headers: headerParameters,
body: bodyParameters,
};
async function updateClientGrant() {
try {
const response = await fetch(endpointUrl, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
updateClientGrant();

Let's look at the highlighted lines from the code shown above:

  • Line 4: We define the URL for the API call and pass the client grant ID as a path parameter.

  • Lines 11–15: We define a bodyParameters object and set the scope values to *. This will allow the client to access all available scopes.

  • Line 25: We make a PATCH request using the fetch function.

  • Line 32: We invoke the updateClientGrant function.

Response fields

The successful execution of the above code returns the client's metadata with the updated values of scope fields.

Deleting a client grant

We can delete this client grant by changing the HTTP method from PATCH to DELETE at line 18 and by removing bodyParameters at line 20 in the code widget above.