Skip to main content

Authentication

Your application must be authenticated to use the Diyalog API. Diyalog uses an AccessKeyId and AccessKeySecret pair for this. First, request the access key id and secret for your application from your Diyalog admin.

Credentials required to make API requests :#
  • AccessKeyId : The access key id created specifically for your application.
  • AccessKeySecret : The secret key created specifically for your application. This key is used to sign your requests.

To call the Diyalog APIs, you must authenticate every request. The Diyalog Platform uses the HMAC Authentication mechanism for authentication.

  • HMAC Authentication

Security#

Transport Layer Security (TLS) is required for authentication. API requests must be encrypted with SSL.

HMAC Authentication#

The Diyalog API uses the HMAC Authentication algorithm and mechanism to authenticate HTTP requests. This mechanism verifies the integrity of each request and that it was made by an authorized application.

After the Diyalog admin user creates the AccessKeyId and AccessKeySecret pair for your application, you must use these credentials to compute the MAC (Message Authentication Code) of every API request with the HMAC SHA256 algorithm and send it in the header of your request. The request time and the employee ID of the person making the request must also be added to the header. The Diyalog Platform uses this information to authenticate your request, after which you will receive a response from the API.

For security, you must use HTTPS/TLS.

The fields you must add to the header of every API request for HMAC authentication are as follows :#
  • x-dlg-date

    The time at which the request is made. It must be in the "EEE, dd MMM yyyy HH:mm:ss Z" format.

    x-dlg-date : "EEE, dd MMM yyyy HH:mm:ss Z"

    For example: x-dlg-date : Tue, 09 Mar 2021 13:28:32 +0000

    • Use English day and month names and a numeric time zone offset such as +0000 or +0300.
    • Make sure your timestamp does not drift more than +/- 15 minutes from the time used by the Diyalog server; otherwise your request will fail.
    • A date the server cannot parse in this format is rejected.
  • x-dlg-requester-userid

    The employee ID of the user making the request, or that user's unique id in your system. This value is used for audit logs.

    x-dlg-requester-userid : “userId of requester”

    For example: x-dlg-requester-userid : 45186

  • x-dlg-authorization

    Your API request is authorized with the request signature you put in this field. The x-dlg-authorization header is built by concatenating the following values.

    x-dlg-authorization : "DLGA " + AccessKeyId + ":" + Signature

    For example : x-dlg-authorization : DLGA 1234567-8ABC-DEF0-5432-56712ABCDEF5:4J2OtxTeMpyfMad4y26RaKA/rrk=

Building the x-dlg-authorization header#

stringToSign = HTTP-method + "\n"
+ Content-Type + "\n"
+ Date + "\n"
+ Body + "\n"
+ RequestPath
Signature = Base64( HMAC-SHA256( AccessKeySecret, UTF-8 bytes of stringToSign ) )
x-dlg-authorization = "DLGA " + AccessKeyId + ":" + Signature
  1. Build the string to sign: the five values below, joined with a newline (\n) between each.
  2. Compute the HMAC-SHA256 of the UTF-8 bytes of that string, using your AccessKeySecret as the key.
  3. Base64-encode the result. This is the signature.
  4. Send DLGA (with a trailing space) + AccessKeyId + : + signature in the x-dlg-authorization header.

The values in the string to sign:

ValueDescription
HTTP-methodThe HTTP method in upper case, e.g. POST or GET.
Content-TypeThe media type the server sees, without parameters. For a JSON body this is always application/json, even if you send application/json; charset=utf-8. For a request with no body and no Content-Type header, it is none/none.
DateExactly the value you send in the x-dlg-date header.
BodyThe request body exactly as sent, as a string. For a request without a body, an empty string.
RequestPathThe path of the request URI, e.g. /v1/reporting/getonlinehelplist for https://<DIYALOG-SERVER-API-ENDPOINT>/v1/reporting/getonlinehelplist.

Example string to sign, with the body sent as compact JSON:

POST
application/json
Tue, 09 Mar 2021 13:28:32 +0000
{"customerId":"2337368","startDate":1764547200000,"endDate":1764633600000}
/v1/reporting/getonlinehelplist
Avoid signature mismatches
  • Sign the exact body you send. Serialize the JSON once and use the same string for the signature and the request. Compact, single-line JSON avoids differences in whitespace and line endings.
  • Sign application/json, not the full header value. Many HTTP clients add ; charset=utf-8 to the Content-Type header (for example .NET StringContent). The server ignores the charset when it builds the string to sign.
  • GET requests: if you send no Content-Type header, sign none/none. If you send Content-Type: application/json with an empty body, sign application/json.
  • Clock: keep the client clock in sync; the date may differ from the server time by at most 15 minutes.

Code examples#

Both examples call the getonlinehelplist Reporting API. They read the API endpoint and credentials from the DIYALOG_API_URL, DIYALOG_ACCESS_KEY_ID and DIYALOG_ACCESS_KEY_SECRET environment variables. They were checked against the server's signature validation on the same HTTP stack the server uses.

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.Locale;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class DiyalogApiExample {
private static final String CONTENT_TYPE = "application/json";
private static final DateTimeFormatter DLG_DATE_FORMAT =
DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
/** Builds the x-dlg-authorization header value: DLGA <accessKeyId>:<signature>. */
static String authorizationHeader(String accessKeyId, String accessKeySecret, String method,
String contentType, String date, String body, String path) throws Exception {
String stringToSign = method + "\n" + contentType + "\n" + date + "\n" + body + "\n" + path;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(accessKeySecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] hmac = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
String signature = Base64.getEncoder().encodeToString(hmac);
return "DLGA " + accessKeyId + ":" + signature;
}
public static void main(String[] args) throws Exception {
String baseUrl = System.getenv().getOrDefault("DIYALOG_API_URL", "https://<DIYALOG-SERVER-API-ENDPOINT>");
String accessKeyId = System.getenv("DIYALOG_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("DIYALOG_ACCESS_KEY_SECRET");
String requesterUserId = "A12345"; // the employee the request is made for; written to the audit log
String path = "/v1/reporting/getonlinehelplist";
// Sign exactly the bytes you send: build the body once and reuse the same string.
String body = "{\"customerId\":\"123456\",\"startDate\":1764547200000,\"endDate\":1764633600000}";
String date = ZonedDateTime.now().format(DLG_DATE_FORMAT);
HttpRequest request = HttpRequest.newBuilder(URI.create(baseUrl + path))
.header("Content-Type", CONTENT_TYPE)
.header("x-dlg-date", date)
.header("x-dlg-requester-userid", requesterUserId)
.header("x-dlg-authorization",
authorizationHeader(accessKeyId, accessKeySecret, "POST", CONTENT_TYPE, date, body, path))
.POST(HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}

Summary#

  1. Get the AccessKeyId and AccessKeySecret for your application from your Diyalog admin.
  2. Build the request body as a string.
  3. Set x-dlg-date to the current time in the EEE, dd MMM yyyy HH:mm:ss Z format.
  4. Set x-dlg-requester-userid to the employee ID (or unique user id in your system) of the person the request is made for.
  5. Build the string to sign from the HTTP method, content type, date, body and request path.
  6. Compute the HMAC-SHA256 of the string with your AccessKeySecret and Base64-encode it.
  7. Set x-dlg-authorization to DLGA + AccessKeyId + : + signature, and send the request over HTTPS.

HMAC Authentication Errors#

If a request cannot be authenticated or authorized, the server returns one of the following errors. The message is returned as plain text.

HTTP statusMessageDescription
400Required headers not foundOne or more of the x-dlg-date, x-dlg-requester-userid or x-dlg-authorization headers are missing.
400Authorization failed due to data format not validThe x-dlg-authorization value after DLGA is not in the AccessKeyId:Signature form.
400Date format is invalid. EEE, dd MMM yyyy HH:mm:ss Z is requiedThe x-dlg-date value cannot be parsed in this format. The message text is returned as shown, including its spelling.
401Authorization failedThe x-dlg-authorization header does not contain DLGA , the AccessKeyId is unknown, or the signature is not correct.
401You have no permission on this operation. Contact your admin.The signature is correct, but your access key has no permission for this API group (for example reporting or push).
403Request time may not be correct.The x-dlg-date value differs from the server time by more than 15 minutes.