# Credentials

A `Credential` represents a verifiable credential which has been issued to the cloud agent via a [credential exchange](https://docs.sudoplatform.com/guides/decentralized-identity/cloud-agent/cloud-agent-admin-api/aries-interop-profile-aip/credential-exchanges), and is currently held by the cloud agent. A `Credential` is a GraphQL union type, so must be resolved to either `AnoncredsCredential` or `W3CCredential`.

Note that credentials which have been *issued by* this cloud agent to a foreign agent are instead found on `AIPCredentialExchange.messages.issued`.

## How to use credentials

Held credentials are primarily used for presenting cryptographically verifiable claims in proof exchanges. See the section on [proof exchanges](https://docs.sudoplatform.com/guides/decentralized-identity/cloud-agent/cloud-agent-admin-api/aries-interop-profile-aip/proof-exchanges) for more information.

## View credentials

View held credentials, with pagination and filtering options. Returns a `nextToken` which can be passed into the same query in order to fetch subsequent pages.

```graphql
query MyQuery {
  credentials(
    page: {
      nextToken: null
    }
    filter: {}
  ) {
    items {
      __typename
      ... on AnoncredsCredential {
        id
        attributes {
          name
          value
        }
        credDefId
        credDef {
          schemaId
        }
      }
      ... on W3CCredential {
        id
        credentialJson
      }
    }
    nextToken
  }
}
```

Alternatively, view a single credential, referenced by its unique ID.

```graphql
query MyQuery {
  credential(
    credentialId: "14eb376d-2b9c-4c30-b40f-ee3ec8250559"
  ) {
    __typename
    ... on AnoncredsCredential {
      id
      attributes {
        name
        value
      }
      credDefId
      credDef {
        schemaId
      }
    }
    ... on W3CCredential {
      id
      credentialJson
    }
  }
}
```

## Delete a credential

Delete a held credential.

```graphql
mutation MyMutation {
  deleteCredential(
    credentialId: "14eb376d-2b9c-4c30-b40f-ee3ec8250559"
  )
}
```
