Disco Docs
Search
K

Programmatically Issue a Credential

General steps to implement based on events in applications and onchain
Programmatically Issue Verifiable Credentials (VCs)
Issue Verifiable Credentials (VCs) programmatically when certain events occur, such as when a user completes specific actions, swaps a token, completes a level in a game, or mints an NFT. VCs can be issued to a user's ETH address or DID. The options are endless and only bound by your imagination!

Prerequisite

Generate a did:web to ensure credentials are signed with keys that you control

How it works

  1. 1.
    Select event(s) that will result in credential issuance
  2. 2.
    Leverage our API endpoint and set up logic in your platform to issue credentials
    • Determine conditions for issuing credentials to a users
    • Send POST requests to the API to issue the credentials
  3. 3.
    User receives credentials

API Endpoint

post
/v1/credential
Programmatically issue one verifiable credential

Generate and return a signed Credential. This will also write the Credential the recipient's data backpack in Disco's Verifiable Data Registry. The JSON body should contain required Credential values for the schema type used. Available schemas and their specifications can be found at https://github.com/discoxyz/disco-schemas.

Parameters
No parameters
Body
Example
Schema
{
"schemaUrl": "https://raw.githubusercontent.com/discoxyz/disco-schemas/main/json/MembershipCredential/1-0-0.json",
"recipientDID": "did:3:Example987xyz",
"subjectData": "{\n \"memberId\": \"Goldstar Member\",\n \"membershipDescription\": \"Demo membership to showcase Disco API\",\n \"membershipLevel\": \"Permanent\",\n \"membershipType\": \"Developer\",\n \"organization\": \"Disco.xyz\"\n }",
"expirationDate": "",
"suite": "",
"issuer": "did:web:api.disco.xyz/v1/disco",
"skipSign": "false"
}
Responses
200: OK
Success
401: Unauthorized
Unauthorized
500: Internal Server Error
Credential not created function captureStackTrace() { [native code] }

Usage example

Curl
JavaScript
curl --location 'https://api.disco.xyz/v1/credential' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Authorization: Bearer <your Disco API key>' \
--data '{
"issuer": "did:3:123abcexample",
"schemaUrl": "https://raw.githubusercontent.com/discoxyz/disco-schemas/main/json/MembershipCredential/1-0-0.json",
"recipientDID": "did:3:456defexample",
"subjectData": {
"memberId": "123XYZ",
"membershipDescription": "Demo membership to showcase Disco API",
"membershipLevel": "Permanent",
"membershipType": "Developer",
"organization": "Disco.xyz"
},
"expirationDate": ""
}'
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Accept", "*/*");
myHeaders.append("Authorization", "Bearer <your Disco API key>");
var raw = JSON.stringify({
"issuer": "did:3:123abcexample",
"schemaUrl": "https://raw.githubusercontent.com/discoxyz/disco-schemas/main/json/MembershipCredential/1-0-0.json",
"recipientDID": "did:3:456defexample",
"subjectData": {
"memberId": "123XYZ",
"membershipDescription": "Demo membership to showcase Disco API",
"membershipLevel": "Permanent",
"membershipType": "Developer",
"organization": "Disco.xyz"
},
"expirationDate": ""
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.disco.xyz/v1/credential", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));