Define & add new credentials

The Credential Schema Structure

Before attesting a credential to a user, you must first define its schema.

A credential consists of two parts: a slug name, which serves as a unique identifier, and a list of fields with their corresponding values.

Property
Type
Required?
Description
Example

slug

String

A unique and descriptive name for the credential schema.

'monthly_expense'

name

String

A short, human-readable name for the credential

'Monthly expense per category'

description

String

A detailed explanation of the credential, including how it’s calculated and how to interpret it. This helps make the credential self-explanatory.

'The average financial expenses over the 90 days preceding the credential’s generation date, calculated using data from Plaid. This includes transactions from both credit cards and bank accounts'

codeUrl

String

A direct URL to the code snippet used to calculate this credential. This promotes transparency and allows others to verify how the credential was generated. The link can point to a GitHub repository or any other trusted source provider

fields

JSON

A payload for the credential, which includes a list of fields and their corresponding values.

{ "name": "expense", "type": "uint", "description": "the dollar value of the average expense" }

Credential field types

Type
Example

uint

130; 5400

string

'USD'; 'Low Fat Milk'

Define a New Credential Schema

POST /api.moojo.id/define-credential

Headers

Name
Value

Content-Type

application/json

x-api-key

Your API KEY as provided by Moojo

Body

Name
Type
Description

slug

string

A unique name of the credential's scheme

fieldDefinitions

Array of objects

An array of fields definition

Request example

{
    "slug": "groceries-expenses",
    "name": "Groceries Expenses",
    "description": "The user’s grocery spending, calculated as the average over the 90 days preceding the credential’s generation date. Based on data provided by MasterCard.",
    "codeUrl": "https://github.com/my-code-url"
    "fieldDefinitions": [  {"name":"monthly-spend",
                            "type":"uint",
                            "description":"The average monthly expense"},
                           {"name":"currency",
                            "type":"string",
                            "description":"3-digit currency code"}
                         ]
}

Response example

{
    "status": "success",
    "traceId": "b1adc9d8-1bb2-43c2-98d7-2ce6573f8b63",
    "data": {
        "credentialDefinition": {
            "slug": "groceries-expenses",
            "name": "Groceries Expenses",
            "description": "The user’s grocery spending, calculated as the average over the 90 days preceding the credential’s generation date. Based on data provided by MasterCard.",
            "codeUrl": "https://github.com/my-code-url"
            "ownerAddress": "0x8b689df125676bafa90b923edc4a92a2ea4b0000"
            "fieldDefinitions": [  {"name":"monthly-spend",
                                    "type":"uint",
                                    "description":"The average monthly expense"},
                                   {"name":"currency",
                                    "type":"string",
                                    "description":"3-digit currency code"}
                                 ]
         }
    }
}

Add a Credential to a User

After defining a credential schema, you can begin adding credentials based on it to users

POST /api.moojo.id/user/add-credential

Headers

Name
Value

Content-Type

application/json

x-api-key

Your API KEY as provided by Moojo

Body

Name
Type
Description

publicUserId

string

The publicUserId of the user receiving the credential. This ID can be found in the response of the user authentication call.

slug

string

The unique name of the credential to be added, as defined by the scheme.

fields

Object

An object containing all fields defined in the scheme along with their corresponding values. See the example below.

Request example

{
  "publicUserId": "{{publicUserId}}",
  "slug": "groceries-expenses",
  "fields": {
    "monthly-spend": 300,
    "currency": "USD"
  }
}

Response example

{
    "status": "success",
    "traceId": "de665302-fb90-4742-85ca-fd399d681fd7",
    "data": {
        "attestedCredential": {
            "createdAt": 1739442337986,
            "issuerAddress": "0x8b689df125676bafa90b923edc4a92a2ea000000",
            "recipientAddress": "0x4e8aefeffaad79fcc520b1c46d09d13ae4000000",
            "slug": "groceries-expenses",
            "fields": {
                "monthly-spend": 300,
                "currency": "USD"
            }
        }
    }
}

Last updated

Was this helpful?