New versions of the Qredo API and Signing Agent are now available! To get started, just contact us here.
Qredo Logo

Qredo API

Add the API key to a Transaction Policy

Overview

This guide explains how to add your API key to a Transaction Policy that is going to govern your Wallet. You can either create a new Transaction Policy with the API key as a Member or update an existing Policy.

Adding your API key to a Transaction Policy is a prerequisite for programmatically approving transactions with the Qredo API or the Signing Agent. Note that your key has to be previously associated with BLS and EC keys or the Signing Agent. To learn about main differences between approving with the Signing Agent and Qredo API, see this guide: Approve requests

Prerequisites

Before you start, take these steps:

  1. Get an API key.

  2. Get an authentication token.

  3. Associate your API key with the Signing Agent (see Steps 2–4) or BLS and EC keys..

  4. In the Qredo Web App, navigate to your Workspace and copy the Workspace ID from the URL:

    https://qredo.network/app/workspace/{workspaceID}
    

Add the key to a new Policy

Step 1: Get the Admin Policy

In this step you'll get the Admin Policy — later you'll use its ID to create a new Transaction Policy.

Call List policies:

GET https://api-v2.qredo.network/api/v2/workspaces/{workspaceID}/policies
  1. Query parameters: In the query, replace {workspaceID} with your Workspace ID from Prerequisites.

  2. Authentication: Pass the auth token as x-token in the request header.

  3. Result: The endpoint will return a list of policies. Find the Admin Policy, then copy its ID from policyID and the human Member (Admin) ID from rules: arguments: id.

    You can identify the Admin Policy by its type — just look for "policyType": "admin" in the response.

    {
        "actionsGoverned": [],
        "expression": {
           "operation": 1,
           "rules": [
               {
                   "arguments": {
                       "id": "m.J7ypd4CFJr6YntophcQryQv2VWonVLHHBfisfBGB7oc7" // the human Member (Admin) ID to copy
                   },
                   "operation": 3,
                   "threshold": 0,
                   "type": 2
               }
           ],
           "threshold": 1,
           "type": 1
        },
        "expressionContentType": "application/json",
        "name": "Workspace Policy",
        "policyID": "2XfVRHhRkfAAy9soj9tEoN105I8", // the Policy ID to copy
        "policyType": "admin", // the Policy type
        "systemType": 0
    }
    

Step 2: Create a Transaction Policy

Please note that this step requires associating your API key with the Signing Agent (see Steps 2–4) or BLS and EC keys. Otherwise, you won't be able to add your API key to the Policy.

In this step you'll create a new Transaction Policy and add your API key as a Member (Approver).

Call Create a Policy:

POST https://api-v2.qredo.network/api/v2/workspaces/{workspaceID}/policies
  1. Query parameters: In the query, replace {workspaceID} with your Workspace ID from Prerequisites.

  2. Body parameters:

    • threshold: The number of approvals required to complete a transaction. Set it to 1.
    • rules: A Policy rule. Add two rules, in arguments: id specify Policy Member IDs:
    • adminPolicyID: The Admin Policy ID obtained in Step 1.
    • policyType: The Policy type. Set it to transaction in order to create a Transaction Policy.
    • Specify other parameters and add more Members if needed.
    {
        "name": "my-policy",
        "expression": {
            "type": 1,
            "operation": 1,
            "threshold": 1, // the Policy threshold
            "rules": [
                {
                    "type": 2, // the rule type — for adding a Member, set to 2
                    "operation": 3,
                    "threshold": 0, // the rule threshold - for adding a Member, set to 0
                    "rules": [],
                    "arguments": {
                        "id": "a.Fpj31XLcApwEfhM6auXt8Xpb7fgtPFmwHyPQLG2Td2yy" // the API key ID
                    },
                },
                {
                    "type": 2,
                    "operation": 3,
                    "threshold": 0,
                    "rules": [],
                    "arguments": {
                        "id": "m.J7ypd4CFJr6YntophcQryQv2VWonVLHHBfisfBGB7oc7" // the human Member ID
                    },
                }
            ],
            "arguments": {}
        },
        "expressionContentType": "application/json",
        "adminPolicyID": "2XfVRHhRkfAAy9soj9tEoN105I8",
        "policyType": "transaction",
        "adminLocked": false,
        "allowDuplicates": false
    }
    

    For each rule in the rules array, you should specify its type and threshold. For adding a Member, like in this example, set the rule type to 2. Threshold in such cases must be set to 0. Note that you can still configure the Policy threshold in another threshold field that is under expression.

  3. Authentication: Pass the auth token as x-token in the request header.

  4. Result: Copy the returned policyID.

Add the key to an existing Policy

Step 1: Get a Transaction Policy

Call List Policies:

GET https://api-v2.qredo.network/api/v2/workspaces/{workspaceID}/policies
  1. Query parameters: In the query, replace {workspaceID} with your Workspace ID from Prerequisites.

  2. Authentication: Pass the auth token as x-token in the request header.

  3. Result: Copy the policyID of the Transaction Policy you wish to use for governing your transactions.

    You can identify your Policy by name and "policyType": "transaction" in the response. For example, here is a Transaction Policy with one human Member:

    {
        "actionsGoverned": [],
        "expression": {
            "operation": 1,
            "rules": [
                {
                    "arguments": {
                        "id": "m.J7ypd4CFJr6YntophcQryQv2VWonVLHHBfisfBGB7oc7" // the human Member ID
                    },
                    "operation": 3,
                    "threshold": 0,
                    "type": 2
                }
            ],
            "threshold": 1,
            "type": 1
        },
        "expressionContentType": "application/json",
        "name": "my-policy", // the name of the Policy
        "policyID": "2SpKjaaX5ieAUDBCtFXBGEcq4JA", // the Policy ID to copy
        "policyType": "transaction", // the Policy type
        "systemType": 0
    }
    

Step 2: Update the Policy

To add your API key as a Member, call Update a Policy:

PUT https://api-v2.qredo.network/api/v2/workspaces/{workspaceID}/policies/{policyID}
  1. Query parameters: In the query, replace {workspaceID} with your Workspace ID from Prerequisites.

  2. Body parameters: You should modify the response returned in Step 1 and use it as your request body. Add an extra rules object, in arguments: id specify your API key:

    {
        "type": 2, // the rule type — for adding a Member, set to 2
        "operation": 3,
        "threshold": 0, // the rule threshold - for adding a Member, set to 0
        "rules": [],
        "arguments": {
            "id": "YOUR_API_KEY" // the API key
        },
    }
    

    Here is an example of a full request body for adding your API key and keeping the human Member:

    {
        "name": "my-policy",
        "expression": {
            "type": 1,
            "operation": 1,
            "threshold": 1, // the Policy threshold
            "rules": [
                {
                    "type": 2, // the rule type — for adding a Member, set to 2
                    "operation": 3,
                    "threshold": 0, // the rule threshold - for adding a Member, set to 0
                    "rules": [],
                    "arguments": {
                        "id": "YOUR_API_KEY" // the API key ID
                    },
                },
                {
                    "type": 2,
                    "operation": 3,
                    "threshold": 0,
                    "rules": [],
                    "arguments": {
                        "id": "m.J7ypd4CFJr6YntophcQryQv2VWonVLHHBfisfBGB7oc7" // the human Member ID
                    },
                }
            ],
            "arguments": {}
        },
        "expressionContentType": "application/json",
        "adminPolicyID": "2XfVRHhRkfAAy9soj9tEoN105I8",
        "policyType": "transaction",
        "adminLocked": false,
        "allowDuplicates": false
    }
    

    For each rule in the rules array, you should specify its type and threshold. For adding a Member, like in this example, set the rule type to 2. Threshold in such cases must be set to 0. Note that you can still configure the Policy threshold in another threshold field that is under expression.

  3. Authentication: Pass the auth token as x-token in the request header.

  4. Result: You created a request for updating the Policy. Authorize and approve it in the Signing App.

    If another API key is already a Member of this Policy, you can approve the request programmatically instead of using the Signing App.

What's next?

Before sending a transaction, prepare your Portfolio and Wallet, as shown in Create a Portfolio and Wallet.

Previous
Approve requests