EQTY LabDocs

Create applied policy credential

Issue a new credential for an applied policy and return the persisted record

posthttps://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials
bash
curl --request POST \
  --url 'https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{"expiresAt":"2030-01-01T00:00:00Z"}'
javascript
const response = await fetch("https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "expiresAt": "2030-01-01T00:00:00Z"
  })
});

const data = await response.json();
typescript
interface AppliedPolicyCredential {
  appliedPolicyId?: number;
  credential?: Record<string, unknown>;
  credentialId?: string;
  expiresAt?: string;
  id?: number;
  issuedAt?: string;
  issuedBy?: string;
  issuedByDid?: string;
  revoked?: boolean;
  revokedAt?: string;
  revokedBy?: string;
  revokedByDid?: string;
  revokedReason?: string;
  sourceCid?: string;
}

const response = await fetch("https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "expiresAt": "2030-01-01T00:00:00Z"
  })
});
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);

const data: AppliedPolicyCredential = await response.json();
python
import requests

response = requests.post(
    "https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials",
    headers={
        "Authorization": "Bearer <token>",
        "Content-Type": "application/json",
    },
    json={
        "expiresAt": "2030-01-01T00:00:00Z",
    },
)
response.raise_for_status()
print(response.json())
go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	body := strings.NewReader(`{
	  "expiresAt": "2030-01-01T00:00:00Z"
	}`)
	req, err := http.NewRequest(http.MethodPost, "https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials", body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer <token>")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(data))
}
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials"))
            .header("Authorization", "Bearer <token>")
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("""
                {
                  "expiresAt": "2030-01-01T00:00:00Z"
                }
                """))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
csharp
using System.Net.Http.Headers;
using System.Text;

using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "<token>");
request.Content = new StringContent("""
    {
      "expiresAt": "2030-01-01T00:00:00Z"
    }
    """, Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
php
<?php

$ch = curl_init('https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer <token>',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => <<<'JSON'
    {
      "expiresAt": "2030-01-01T00:00:00Z"
    }
    JSON,
    CURLOPT_RETURNTRANSFER => true,
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo $status . " " . $response . PHP_EOL;
ruby
require "net/http"

uri = URI("https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = <<~'JSON'
  {
    "expiresAt": "2030-01-01T00:00:00Z"
  }
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end
puts "#{response.code} #{response.body}"
rust
// Cargo.toml dependencies: reqwest (features "json"), serde_json, tokio (features "full")
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::Client::new()
        .post("https://localhost:10001/api/v1/projects/{projectId}/policies/{appliedPolicyId}/credentials")
        .header("Authorization", "Bearer <token>")
        .json(&json!({
            "expiresAt": "2030-01-01T00:00:00Z"
        }))
        .send()
        .await?;

    println!("{} {}", response.status(), response.text().await?);
    Ok(())
}

Authorizations

  • BearerAuth · API key in header "Authorization" — Type "Bearer" followed by a space and JWT token.

Parameters

Path parameters

NameTypeDescription
projectId
required
string

Project ID, UUID (urn:uuid optional), or slug:my-project

appliedPolicyId
required
string

Applied policy ID, slug:my-policy, or urn:cid:bafy...

Request bodyrequired

Applied policy credential issuance request

application/json
  • expiresAtstring<date-time>required

    Must be in the future

Examplejson
{
  "expiresAt": "2030-01-01T00:00:00Z"
}

Responses

201Created credential

application/json
  • appliedPolicyIdintegerread-only

    Taken from the path on create

  • credentialobjectread-only
  • credentialIdstringread-only

    urn:uuid minted per issuance; identifies the row

  • expiresAtstring<date-time>
  • idintegerread-only
  • issuedAtstring<date-time>read-only
  • issuedBystringread-only
  • issuedByDidstringread-only

    Verifiable actor; issuedBy is the label

  • revokedbooleanread-only

    Set via the revoke endpoint

  • revokedAtstring<date-time>read-only

    Set via the revoke endpoint

  • revokedBystringread-only

    Set via the revoke endpoint

  • revokedByDidstringread-only

    Verifiable actor; revokedBy is the label

  • revokedReasonstringread-only

    Set via the revoke endpoint

  • sourceCidstringread-only

    Assigned by the Integrity Service

Examplejson
{
  "appliedPolicyId": 0,
  "credential": {},
  "credentialId": "string",
  "expiresAt": "2025-01-01T00:00:00Z",
  "id": 0,
  "issuedAt": "2025-01-01T00:00:00Z",
  "issuedBy": "string",
  "issuedByDid": "string",
  "revoked": true,
  "revokedAt": "2025-01-01T00:00:00Z",
  "revokedBy": "string",
  "revokedByDid": "string",
  "revokedReason": "string",
  "sourceCid": "string"
}

400Bad request - Invalid IDs or request body

application/json
  • errorstring
Examplejson
{
  "error": "Invalid request body"
}

401Unauthorized - Authentication required

application/json
  • errorstring
Examplejson
{
  "error": "Invalid request body"
}

403Forbidden - No project access or insufficient permissions

application/json
  • errorstring
Examplejson
{
  "error": "Invalid request body"
}

409Credential already issued

application/json
  • errorstring
Examplejson
{
  "error": "Invalid request body"
}

500Internal server error

application/json
  • errorstring
Examplejson
{
  "error": "Invalid request body"
}