This document outlines how to interact with the CredoID REST API. This API provides access to resources of the CredoID Access Control Software. All requests and responses are formatted in JSON (JavaScript Object Notation).
The base URL for all the API endpoints is http://localhost:8090/api
.
All API requests must be authorized with a JWT token. You can obtain this key from a login endpoint. Once you have your API key, you can provide it in the Authorization
header of your requests like this:
Authorization: Bearer my_token
For more information about the available API endpoints, please refer to our Swagger documentation at http://localhost:8090/swagger/index.html
API is split into these categories:
Here is an example of how to make a request to the CredoID API in C#. In this example, we use the HttpClient class in the System.Net.Http namespace to make HTTP requests. The /api/login
endpoint is used to authenticate a user and obtain a JWT bearer token. This token is required for most other API calls.
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
var loginResponse = await Login("admin", "admin");
Console.WriteLine(loginResponse);
}
static async Task<string> Login(string username, string password)
{
var requestBody = new
{
username = username,
password = password
};
var content = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://demo.credoid.com/api/login", content);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<dynamic>(responseContent).token;
}
}
NOTE: in example public demo CredoID address is used, when testing you should replace it with your own.
If the login attempt is successful, the server will respond with a 200 OK
status code and a JSON body containing the bearer token:
{
"token": "<bearer_token>"
}
This token should be used in the Authorization header for subsequent API calls.
GET /api/users
endpointThe /api/users
endpoint is used to retrieve a list of all users.
https://localhost:8090/api/users
Include the following header in your request:
Authorization: Bearer <your_bearer_token>
Successful requests will return a 200 OK
status code along with a JSON array containing user objects. Example output:
[
{
"id": 1,
"firstName": "John",
"lastName": "Doe",
"companyName": "ACME Corp.",
"departmentName": "Sales",
"userTitleName": "Sales Manager",
"employeeNumber": "JD123",
"email": "johndoe@example.com",
"phoneNumber": "+1234567890",
"version": "1.0",
"companyId": 101,
"departmentId": 201,
"titleId": 301,
"activationDate": "2023-06-01T00:00:00",
"expirationDate": "2023-12-31T23:59:59",
"hasImage": true
},
{
"id": 2,
"firstName": "Jane",
"lastName": "Smith",
"companyName": "ACME Corp.",
"departmentName": "Marketing",
"userTitleName": "Marketing Executive",
"employeeNumber": "JS456",
"email": "janesmith@example.com",
"phoneNumber": "+0987654321",
"version": "1.0",
"companyId": 101,
"departmentId": 202,
"titleId": 302,
"activationDate": "2023-06-01T00:00:00",
"expirationDate": null,
"hasImage": false
}
]
For any questions or issues regarding the API, please get in touch with our support team at https://credoid.atlassian.net/servicedesk/customer/portal/2.