curl --request GET \
--url 'https://YOURSITE.konstant.ly/openapi/v1/certificates/123' \
--header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
import requests
from typing import Dict
def get_certificate(api_key: str, certificate_id: int) -> Dict:
url = f"https://YOURSITE.konstant.ly/openapi/v1/certificates/{certificate_id}"
headers = {
"X-API-KEY": api_key
}
try:
response = requests.get(url, headers=headers)
if response.status_code == 404:
raise ValueError(f"Certificate {certificate_id} not found")
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error getting certificate: {str(e)}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response: {e.response.text}")
raise
# Example usage
if __name__ == "__main__":
try:
certificate = get_certificate("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv", 123)
print(f"Certificate: {certificate['name']}")
print(f"Course: {certificate['courseName']}")
print(f"Issued to: {certificate['user']['name']}")
print(f"Achieved at: {certificate['achievedAt']}")
if certificate.get('expiresAt'):
print(f"Expires at: {certificate['expiresAt']}")
except ValueError as e:
print(f"Error: {str(e)}")
except Exception as e:
print(f"Failed to get certificate: {str(e)}")
const axios = require('axios');
class CertificatesAPI {
constructor(apiKey) {
this.client = axios.create({
baseURL: 'https://YOURSITE.konstant.ly/openapi/v1',
headers: {
'X-API-KEY': apiKey
}
});
}
async getCertificate(certificateId) {
try {
const response = await this.client.get(`/certificates/${certificateId}`);
return response.data;
} catch (error) {
if (error.response?.status === 404) {
throw new Error(`Certificate ${certificateId} not found`);
}
throw new Error(`Failed to get certificate: ${error.response?.data?.message || error.message}`);
}
}
// Helper method to format certificate details
formatCertificateInfo(certificate) {
return {
certificateName: certificate.name,
courseName: certificate.courseName,
issuedTo: certificate.user.name,
achievedAt: new Date(certificate.achievedAt * 1000).toLocaleString(),
expiresAt: certificate.expiresAt ?
new Date(certificate.expiresAt * 1000).toLocaleString() :
'Never'
};
}
}
// Example usage
async function main() {
const certificatesApi = new CertificatesAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
try {
const certificate = await certificatesApi.getCertificate(123);
const info = certificatesApi.formatCertificateInfo(certificate);
console.log('Certificate Details:');
console.log(`Name: ${info.certificateName}`);
console.log(`Course: ${info.courseName}`);
console.log(`Issued to: ${info.issuedTo}`);
console.log(`Achieved at: ${info.achievedAt}`);
console.log(`Expires at: ${info.expiresAt}`);
} catch (error) {
console.error('Failed to get certificate:', error.message);
}
}
main();
<?php
class CertificatesAPI {
private $apiKey;
private $baseUrl;
public function __construct($apiKey) {
$this->apiKey = $apiKey;
$this->baseUrl = 'https://YOURSITE.konstant.ly/openapi/v1';
}
public function getCertificate($certificateId) {
$ch = curl_init();
$url = "{$this->baseUrl}/certificates/{$certificateId}";
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-KEY: ' . $this->apiKey
]
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
throw new Exception('Error: ' . curl_error($ch));
}
curl_close($ch);
if ($httpCode === 404) {
throw new Exception("Certificate $certificateId not found");
}
if ($httpCode !== 200) {
throw new Exception("Failed to get certificate. Status code: $httpCode");
}
return json_decode($response, true);
}
// Helper method to format certificate details
public function formatCertificateInfo($certificate) {
return [
'certificateName' => $certificate['name'],
'courseName' => $certificate['courseName'],
'issuedTo' => $certificate['user']['name'],
'achievedAt' => date('Y-m-d H:i:s', $certificate['achievedAt']),
'expiresAt' => isset($certificate['expiresAt']) ?
date('Y-m-d H:i:s', $certificate['expiresAt']) :
'Never'
];
}
}
// Example usage
try {
$certificatesApi = new CertificatesAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
$certificate = $certificatesApi->getCertificate(123);
$info = $certificatesApi->formatCertificateInfo($certificate);
echo "Certificate Details:\n";
echo "Name: {$info['certificateName']}\n";
echo "Course: {$info['courseName']}\n";
echo "Issued to: {$info['issuedTo']}\n";
echo "Achieved at: {$info['achievedAt']}\n";
echo "Expires at: {$info['expiresAt']}\n";
} catch (Exception $e) {
echo "Failed to get certificate: " . $e->getMessage() . "\n";
}
?>
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
public class CertificatesAPI {
private static final String API_KEY = "1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv";
private static final String BASE_URL = "https://YOURSITE.konstant.ly/openapi/v1";
private final HttpClient client = HttpClient.newHttpClient();
private final ObjectMapper mapper = new ObjectMapper();
public Map<String, Object> getCertificate(int certificateId) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URL + "/certificates/" + certificateId))
.header("X-API-KEY", API_KEY)
.GET()
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 404) {
throw new Exception("Certificate " + certificateId + " not found");
}
if (response.statusCode() != 200) {
throw new Exception("Failed to get certificate. Status: " + response.statusCode());
}
return mapper.readValue(response.body(), Map.class);
}
// Helper method to format certificate details
public static class CertificateInfo {
public final String certificateName;
public final String courseName;
public final String issuedTo;
public final LocalDateTime achievedAt;
public final LocalDateTime expiresAt;
public CertificateInfo(Map<String, Object> certificate) {
this.certificateName = (String) certificate.get("name");
this.courseName = (String) certificate.get("courseName");
Map<String, Object> user = (Map<String, Object>) certificate.get("user");
this.issuedTo = (String) user.get("name");
this.achievedAt = LocalDateTime.ofInstant(
Instant.ofEpochSecond(((Number) certificate.get("achievedAt")).longValue()),
ZoneId.systemDefault()
);
if (certificate.get("expiresAt") != null) {
this.expiresAt = LocalDateTime.ofInstant(
Instant.ofEpochSecond(((Number) certificate.get("expiresAt")).longValue()),
ZoneId.systemDefault()
);
} else {
this.expiresAt = null;
}
}
}
public static void main(String[] args) {
CertificatesAPI api = new CertificatesAPI();
try {
Map<String, Object> certificate = api.getCertificate(123);
CertificateInfo info = new CertificateInfo(certificate);
System.out.println("Certificate Details:");
System.out.println("Name: " + info.certificateName);
System.out.println("Course: " + info.courseName);
System.out.println("Issued to: " + info.issuedTo);
System.out.println("Achieved at: " + info.achievedAt);
System.out.println("Expires at: " +
(info.expiresAt != null ? info.expiresAt : "Never"));
} catch (Exception e) {
System.err.println("Failed to get certificate: " + e.getMessage());
e.printStackTrace();
}
}
}
{
"id": 123,
"name": "Course Completion Certificate",
"description": "Certificate of completion for Advanced Marketing Course",
"courseId": 2,
"courseName": "Advanced Marketing",
"imageUrl": "http://s3.amazonaws.com/qwerty/certificate.png",
"achievedAt": 1234567890,
"expiresAt": 1334567890,
"user": {
"id": "1234567890",
"name": "John Smith",
"email": "john@example.com",
"language": "en",
"timezone": "Europe/London",
"occupation": "Marketing Manager",
"location": "London",
"isBanned": false,
"role": {
"alias": "learner"
},
"fromApi": false,
"image": null,
"attributes": {}
}
}
{
"status": 404,
"message": "Not found"
}
Certificates
Get Certificate
Get a certificate by ID
GET
/
certificates
/
{certificateId}
curl --request GET \
--url 'https://YOURSITE.konstant.ly/openapi/v1/certificates/123' \
--header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
import requests
from typing import Dict
def get_certificate(api_key: str, certificate_id: int) -> Dict:
url = f"https://YOURSITE.konstant.ly/openapi/v1/certificates/{certificate_id}"
headers = {
"X-API-KEY": api_key
}
try:
response = requests.get(url, headers=headers)
if response.status_code == 404:
raise ValueError(f"Certificate {certificate_id} not found")
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error getting certificate: {str(e)}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response: {e.response.text}")
raise
# Example usage
if __name__ == "__main__":
try:
certificate = get_certificate("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv", 123)
print(f"Certificate: {certificate['name']}")
print(f"Course: {certificate['courseName']}")
print(f"Issued to: {certificate['user']['name']}")
print(f"Achieved at: {certificate['achievedAt']}")
if certificate.get('expiresAt'):
print(f"Expires at: {certificate['expiresAt']}")
except ValueError as e:
print(f"Error: {str(e)}")
except Exception as e:
print(f"Failed to get certificate: {str(e)}")
const axios = require('axios');
class CertificatesAPI {
constructor(apiKey) {
this.client = axios.create({
baseURL: 'https://YOURSITE.konstant.ly/openapi/v1',
headers: {
'X-API-KEY': apiKey
}
});
}
async getCertificate(certificateId) {
try {
const response = await this.client.get(`/certificates/${certificateId}`);
return response.data;
} catch (error) {
if (error.response?.status === 404) {
throw new Error(`Certificate ${certificateId} not found`);
}
throw new Error(`Failed to get certificate: ${error.response?.data?.message || error.message}`);
}
}
// Helper method to format certificate details
formatCertificateInfo(certificate) {
return {
certificateName: certificate.name,
courseName: certificate.courseName,
issuedTo: certificate.user.name,
achievedAt: new Date(certificate.achievedAt * 1000).toLocaleString(),
expiresAt: certificate.expiresAt ?
new Date(certificate.expiresAt * 1000).toLocaleString() :
'Never'
};
}
}
// Example usage
async function main() {
const certificatesApi = new CertificatesAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
try {
const certificate = await certificatesApi.getCertificate(123);
const info = certificatesApi.formatCertificateInfo(certificate);
console.log('Certificate Details:');
console.log(`Name: ${info.certificateName}`);
console.log(`Course: ${info.courseName}`);
console.log(`Issued to: ${info.issuedTo}`);
console.log(`Achieved at: ${info.achievedAt}`);
console.log(`Expires at: ${info.expiresAt}`);
} catch (error) {
console.error('Failed to get certificate:', error.message);
}
}
main();
<?php
class CertificatesAPI {
private $apiKey;
private $baseUrl;
public function __construct($apiKey) {
$this->apiKey = $apiKey;
$this->baseUrl = 'https://YOURSITE.konstant.ly/openapi/v1';
}
public function getCertificate($certificateId) {
$ch = curl_init();
$url = "{$this->baseUrl}/certificates/{$certificateId}";
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-KEY: ' . $this->apiKey
]
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
throw new Exception('Error: ' . curl_error($ch));
}
curl_close($ch);
if ($httpCode === 404) {
throw new Exception("Certificate $certificateId not found");
}
if ($httpCode !== 200) {
throw new Exception("Failed to get certificate. Status code: $httpCode");
}
return json_decode($response, true);
}
// Helper method to format certificate details
public function formatCertificateInfo($certificate) {
return [
'certificateName' => $certificate['name'],
'courseName' => $certificate['courseName'],
'issuedTo' => $certificate['user']['name'],
'achievedAt' => date('Y-m-d H:i:s', $certificate['achievedAt']),
'expiresAt' => isset($certificate['expiresAt']) ?
date('Y-m-d H:i:s', $certificate['expiresAt']) :
'Never'
];
}
}
// Example usage
try {
$certificatesApi = new CertificatesAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
$certificate = $certificatesApi->getCertificate(123);
$info = $certificatesApi->formatCertificateInfo($certificate);
echo "Certificate Details:\n";
echo "Name: {$info['certificateName']}\n";
echo "Course: {$info['courseName']}\n";
echo "Issued to: {$info['issuedTo']}\n";
echo "Achieved at: {$info['achievedAt']}\n";
echo "Expires at: {$info['expiresAt']}\n";
} catch (Exception $e) {
echo "Failed to get certificate: " . $e->getMessage() . "\n";
}
?>
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
public class CertificatesAPI {
private static final String API_KEY = "1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv";
private static final String BASE_URL = "https://YOURSITE.konstant.ly/openapi/v1";
private final HttpClient client = HttpClient.newHttpClient();
private final ObjectMapper mapper = new ObjectMapper();
public Map<String, Object> getCertificate(int certificateId) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URL + "/certificates/" + certificateId))
.header("X-API-KEY", API_KEY)
.GET()
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 404) {
throw new Exception("Certificate " + certificateId + " not found");
}
if (response.statusCode() != 200) {
throw new Exception("Failed to get certificate. Status: " + response.statusCode());
}
return mapper.readValue(response.body(), Map.class);
}
// Helper method to format certificate details
public static class CertificateInfo {
public final String certificateName;
public final String courseName;
public final String issuedTo;
public final LocalDateTime achievedAt;
public final LocalDateTime expiresAt;
public CertificateInfo(Map<String, Object> certificate) {
this.certificateName = (String) certificate.get("name");
this.courseName = (String) certificate.get("courseName");
Map<String, Object> user = (Map<String, Object>) certificate.get("user");
this.issuedTo = (String) user.get("name");
this.achievedAt = LocalDateTime.ofInstant(
Instant.ofEpochSecond(((Number) certificate.get("achievedAt")).longValue()),
ZoneId.systemDefault()
);
if (certificate.get("expiresAt") != null) {
this.expiresAt = LocalDateTime.ofInstant(
Instant.ofEpochSecond(((Number) certificate.get("expiresAt")).longValue()),
ZoneId.systemDefault()
);
} else {
this.expiresAt = null;
}
}
}
public static void main(String[] args) {
CertificatesAPI api = new CertificatesAPI();
try {
Map<String, Object> certificate = api.getCertificate(123);
CertificateInfo info = new CertificateInfo(certificate);
System.out.println("Certificate Details:");
System.out.println("Name: " + info.certificateName);
System.out.println("Course: " + info.courseName);
System.out.println("Issued to: " + info.issuedTo);
System.out.println("Achieved at: " + info.achievedAt);
System.out.println("Expires at: " +
(info.expiresAt != null ? info.expiresAt : "Never"));
} catch (Exception e) {
System.err.println("Failed to get certificate: " + e.getMessage());
e.printStackTrace();
}
}
}
{
"id": 123,
"name": "Course Completion Certificate",
"description": "Certificate of completion for Advanced Marketing Course",
"courseId": 2,
"courseName": "Advanced Marketing",
"imageUrl": "http://s3.amazonaws.com/qwerty/certificate.png",
"achievedAt": 1234567890,
"expiresAt": 1334567890,
"user": {
"id": "1234567890",
"name": "John Smith",
"email": "john@example.com",
"language": "en",
"timezone": "Europe/London",
"occupation": "Marketing Manager",
"location": "London",
"isBanned": false,
"role": {
"alias": "learner"
},
"fromApi": false,
"image": null,
"attributes": {}
}
}
{
"status": 404,
"message": "Not found"
}
Retrieve detailed information about a specific certificate.
Path Parameters
integer
required
The unique identifier of the certificate
Request Headers
string
required
API Key. Go to your Konstantly site > Settings > API and copy the value from there.
Response
integer
required
Certificate ID
string
required
Certificate name
string
required
Certificate description
integer
required
Course ID
string
required
Course name
string
required
URL to the certificate image
integer
required
Timestamp of certificate issue
integer
Timestamp when the certificate expires
object
required
User who has got the certificate
Show User Object
Show User Object
string
required
User ID
string
required
Full name
string
required
Interface language (de, en, es, fr, pl, pt, ru)
string
Job title (optional)
string
User location (optional)
string
required
User timezone in TZ format
string
required
Email address
boolean
required
User ban status
object
required
User role information
boolean
required
Whether created via API
object
User avatar information
object
Custom user attributes
Error Responses
object
curl --request GET \
--url 'https://YOURSITE.konstant.ly/openapi/v1/certificates/123' \
--header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
import requests
from typing import Dict
def get_certificate(api_key: str, certificate_id: int) -> Dict:
url = f"https://YOURSITE.konstant.ly/openapi/v1/certificates/{certificate_id}"
headers = {
"X-API-KEY": api_key
}
try:
response = requests.get(url, headers=headers)
if response.status_code == 404:
raise ValueError(f"Certificate {certificate_id} not found")
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error getting certificate: {str(e)}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response: {e.response.text}")
raise
# Example usage
if __name__ == "__main__":
try:
certificate = get_certificate("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv", 123)
print(f"Certificate: {certificate['name']}")
print(f"Course: {certificate['courseName']}")
print(f"Issued to: {certificate['user']['name']}")
print(f"Achieved at: {certificate['achievedAt']}")
if certificate.get('expiresAt'):
print(f"Expires at: {certificate['expiresAt']}")
except ValueError as e:
print(f"Error: {str(e)}")
except Exception as e:
print(f"Failed to get certificate: {str(e)}")
const axios = require('axios');
class CertificatesAPI {
constructor(apiKey) {
this.client = axios.create({
baseURL: 'https://YOURSITE.konstant.ly/openapi/v1',
headers: {
'X-API-KEY': apiKey
}
});
}
async getCertificate(certificateId) {
try {
const response = await this.client.get(`/certificates/${certificateId}`);
return response.data;
} catch (error) {
if (error.response?.status === 404) {
throw new Error(`Certificate ${certificateId} not found`);
}
throw new Error(`Failed to get certificate: ${error.response?.data?.message || error.message}`);
}
}
// Helper method to format certificate details
formatCertificateInfo(certificate) {
return {
certificateName: certificate.name,
courseName: certificate.courseName,
issuedTo: certificate.user.name,
achievedAt: new Date(certificate.achievedAt * 1000).toLocaleString(),
expiresAt: certificate.expiresAt ?
new Date(certificate.expiresAt * 1000).toLocaleString() :
'Never'
};
}
}
// Example usage
async function main() {
const certificatesApi = new CertificatesAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
try {
const certificate = await certificatesApi.getCertificate(123);
const info = certificatesApi.formatCertificateInfo(certificate);
console.log('Certificate Details:');
console.log(`Name: ${info.certificateName}`);
console.log(`Course: ${info.courseName}`);
console.log(`Issued to: ${info.issuedTo}`);
console.log(`Achieved at: ${info.achievedAt}`);
console.log(`Expires at: ${info.expiresAt}`);
} catch (error) {
console.error('Failed to get certificate:', error.message);
}
}
main();
<?php
class CertificatesAPI {
private $apiKey;
private $baseUrl;
public function __construct($apiKey) {
$this->apiKey = $apiKey;
$this->baseUrl = 'https://YOURSITE.konstant.ly/openapi/v1';
}
public function getCertificate($certificateId) {
$ch = curl_init();
$url = "{$this->baseUrl}/certificates/{$certificateId}";
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-KEY: ' . $this->apiKey
]
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
throw new Exception('Error: ' . curl_error($ch));
}
curl_close($ch);
if ($httpCode === 404) {
throw new Exception("Certificate $certificateId not found");
}
if ($httpCode !== 200) {
throw new Exception("Failed to get certificate. Status code: $httpCode");
}
return json_decode($response, true);
}
// Helper method to format certificate details
public function formatCertificateInfo($certificate) {
return [
'certificateName' => $certificate['name'],
'courseName' => $certificate['courseName'],
'issuedTo' => $certificate['user']['name'],
'achievedAt' => date('Y-m-d H:i:s', $certificate['achievedAt']),
'expiresAt' => isset($certificate['expiresAt']) ?
date('Y-m-d H:i:s', $certificate['expiresAt']) :
'Never'
];
}
}
// Example usage
try {
$certificatesApi = new CertificatesAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
$certificate = $certificatesApi->getCertificate(123);
$info = $certificatesApi->formatCertificateInfo($certificate);
echo "Certificate Details:\n";
echo "Name: {$info['certificateName']}\n";
echo "Course: {$info['courseName']}\n";
echo "Issued to: {$info['issuedTo']}\n";
echo "Achieved at: {$info['achievedAt']}\n";
echo "Expires at: {$info['expiresAt']}\n";
} catch (Exception $e) {
echo "Failed to get certificate: " . $e->getMessage() . "\n";
}
?>
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
public class CertificatesAPI {
private static final String API_KEY = "1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv";
private static final String BASE_URL = "https://YOURSITE.konstant.ly/openapi/v1";
private final HttpClient client = HttpClient.newHttpClient();
private final ObjectMapper mapper = new ObjectMapper();
public Map<String, Object> getCertificate(int certificateId) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URL + "/certificates/" + certificateId))
.header("X-API-KEY", API_KEY)
.GET()
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 404) {
throw new Exception("Certificate " + certificateId + " not found");
}
if (response.statusCode() != 200) {
throw new Exception("Failed to get certificate. Status: " + response.statusCode());
}
return mapper.readValue(response.body(), Map.class);
}
// Helper method to format certificate details
public static class CertificateInfo {
public final String certificateName;
public final String courseName;
public final String issuedTo;
public final LocalDateTime achievedAt;
public final LocalDateTime expiresAt;
public CertificateInfo(Map<String, Object> certificate) {
this.certificateName = (String) certificate.get("name");
this.courseName = (String) certificate.get("courseName");
Map<String, Object> user = (Map<String, Object>) certificate.get("user");
this.issuedTo = (String) user.get("name");
this.achievedAt = LocalDateTime.ofInstant(
Instant.ofEpochSecond(((Number) certificate.get("achievedAt")).longValue()),
ZoneId.systemDefault()
);
if (certificate.get("expiresAt") != null) {
this.expiresAt = LocalDateTime.ofInstant(
Instant.ofEpochSecond(((Number) certificate.get("expiresAt")).longValue()),
ZoneId.systemDefault()
);
} else {
this.expiresAt = null;
}
}
}
public static void main(String[] args) {
CertificatesAPI api = new CertificatesAPI();
try {
Map<String, Object> certificate = api.getCertificate(123);
CertificateInfo info = new CertificateInfo(certificate);
System.out.println("Certificate Details:");
System.out.println("Name: " + info.certificateName);
System.out.println("Course: " + info.courseName);
System.out.println("Issued to: " + info.issuedTo);
System.out.println("Achieved at: " + info.achievedAt);
System.out.println("Expires at: " +
(info.expiresAt != null ? info.expiresAt : "Never"));
} catch (Exception e) {
System.err.println("Failed to get certificate: " + e.getMessage());
e.printStackTrace();
}
}
}
{
"id": 123,
"name": "Course Completion Certificate",
"description": "Certificate of completion for Advanced Marketing Course",
"courseId": 2,
"courseName": "Advanced Marketing",
"imageUrl": "http://s3.amazonaws.com/qwerty/certificate.png",
"achievedAt": 1234567890,
"expiresAt": 1334567890,
"user": {
"id": "1234567890",
"name": "John Smith",
"email": "john@example.com",
"language": "en",
"timezone": "Europe/London",
"occupation": "Marketing Manager",
"location": "London",
"isBanned": false,
"role": {
"alias": "learner"
},
"fromApi": false,
"image": null,
"attributes": {}
}
}
{
"status": 404,
"message": "Not found"
}
Was this page helpful?
⌘I