# Get and Delete Consents
source: https://developer.mastercard.com/consent-management/documentation/tutorials-and-guides/card-consents-tutorial/get-and-delete-consents/index.md

## Overview {#overview}

After a consent is approved, the reference app displays the **Consents** info page. From this page you can retrieve all consents for a card, delete a specific consent, or delete all consents at once.

![<strong>Consents</strong> info page showing the card reference and action buttons](https://static.developer.mastercard.com/content/consent-management/img/ref-app-card-consent-response.png)

## Get Consents {#get-consents}

To retrieve the consents associated with the enrolled card, select **Get Card Consents** on the **Consents** info page. The reference app calls `GET /consents/{cardReference}` and displays each consent in a list.

![Consent list displayed after selecting Get Card Consents](https://static.developer.mastercard.com/content/consent-management/documentation/images/ref-app-card-consent-get-consents.png)

### Implementation {#implementation}

* Java
* Python

```java
// ConsentsController.java

  @GetMapping("/getConsents")
  public ResponseEntity<Consents> getConsents(@RequestParam String reference) {
    try {
      Consents consents = apiService.getApiClient().getConsents(reference);
      return new ResponseEntity<>(consents, HttpStatus.OK);
    } catch (Exception e) {
      log.error(e.getMessage());
    }
    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
  }
```

```python
@app.route("/getConsents")
def get_consents():
    reference = request.args.get('reference')
    resp = api_get_consents(reference)
    return resp
```

### Response {#response}

The response contains the `cardReference` and a `consents` array. Each consent includes an `id`, `name`, and `status`.

```json
{
    "cardReference": "9ce4fd0d-0fdb-4367-9854-fb2c6fa66eb1",
    "consents": [
        {
            "id": "12345",
            "status": "APPROVED",
            "name": "notification"
        }
    ]
}
```

If the `cardReference` does not exist, the API returns a `404 Not Found` response.

## Delete All Consents {#delete-all-consents}

To revoke all consents and unenroll the card from the Transaction Notifications service, select **Delete All Consents** on the **Consents** info page. The reference app calls `DELETE /consents/{cardReference}` and removes every consent for that card.

### Implementation {#implementation-1}

* Java
* Python

```java
// ConsentsController.java

  @DeleteMapping("/deleteConsents")
  public ResponseEntity<Void> deleteConsents(@RequestParam String reference) {
    try {
      apiService.getApiClient().deleteConsents(reference);
      return ResponseEntity.ok().build();
    } catch (Exception e) {
      log.error(e.getMessage());
    }
    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
  }
```

```python
@app.route("/deleteConsents", methods=['DELETE'])
def delete_consents():
    reference = request.args.get('reference')
    resp = api_delete_consents(reference)
    return resp
```

### Response {#response-1}

A successful delete returns `200 OK` with an empty response body. A subsequent `GET /consents/{cardReference}` returns `404 Not Found`, confirming the consents have been removed.

## Delete a Specific Consent {#delete-a-specific-consent}

To revoke a single consent without affecting others on the same card, first retrieve the consent list by selecting **Get Card Consents** . Each consent in the list displays a **Delete** link. Select the link next to the consent you want to revoke. The reference app calls `DELETE /consents/{cardReference}/consents/{consentId}` to remove only that consent.

### Implementation {#implementation-2}

* Java
* Python

```java
// ConsentsController.java

  @DeleteMapping("/deleteConsent")
  public ResponseEntity<Void> deleteConsent(@RequestParam String reference, @RequestParam String consentId) {
    try {
      apiService.getApiClient().deleteConsent(reference, consentId);
      return ResponseEntity.ok().build();
    } catch (Exception e) {
      log.error(e.getMessage());
    }
    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
  }
```

```python
@app.route("/deleteConsent", methods=['DELETE'])
def delete_consent():
    reference = request.args.get('reference')
    consent_id = request.args.get('consentId')
    resp = api_delete_consent(reference, consent_id)
    return resp
```

The `consent_id` is taken from the consent list returned by the Get Consents call.

## Next Steps {#next-steps}

* Review the [Testing](https://developer.mastercard.com/consent-management/documentation/testing/index.md) page for test cases covering Get Consents and Delete Consents scenarios.
* See the [API Reference](https://developer.mastercard.com/consent-management/documentation/api-reference/index.md) for full request and response details.
