Skip to main content

Step 5: Consent Creation

Once you have:

  • ✅ Generated the Access Token (Step 3)
  • ✅ Published a consent notice and prepared the Consent Request (Step 4)

You are now ready to create a Consent Request.


Endpoint​

Method: POST URL: /api/cm/v1/df/consent-requests

Environment Base URLs​

Staging: https://staging.indiaconsent.com/api/cm/v1/df/consent-requests

Production: https://www.indiaconsent.com/api/cm/v1/df/consent-requests


Request Headers​

HeaderValue
Content-Typeapplication/json
AuthorizationBearer <accessToken>

Sample Request​

POST /api/cm/v1/df/consent-requests
Authorization: Bearer <accessToken>
Content-Type: application/json


{
"requestId": "3c14b629-ae66-48f1-b5d7-cafc2078c1a4",
"notice": {
"noticeId": "c6808a21-3e86-4d9a-9de5-a849b427f5c6",
"version": 3
},
"dataPrincipal": {
"dpHash": "68fb2ced2daaf430ebd5c9eb",
"subjectType": "ADULT"
}
}

Sample Code​


import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class ConsentCreation {

private static final String CONSENT_MGR_URL = "https://staging.indiaconsent.com";

public static void main(String[] args) throws Exception {

String token = "<TOKEN>"; // Replace with actual token from step 3

String payload = "<PAYLOAD>"; // Replace with actual payload from step 4

HttpRequest consentRequest = HttpRequest.newBuilder()
.uri(URI.create(CONSENT_MGR_URL + "/api/cm/v1/df/consent-requests"))
.POST(HttpRequest.BodyPublishers.ofString(payload))
.header("Authorization", "Bearer " + token)
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(15))
.build();

HttpClient httpClient = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build();

HttpResponse<String> consentResponse = httpClient.send(
consentRequest,
HttpResponse.BodyHandlers.ofString()
);

if (consentResponse.statusCode() != 200
&& consentResponse.statusCode() != 201) {
throw new RuntimeException("Consent API failed: " + consentResponse.body());
}

String redirectUrl = extractJsonValue(
consentResponse.body(),
"redirectUrl"
);

if (redirectUrl == null) {
throw new RuntimeException("redirectUrl not found in response");
}

System.out.println("Redirect URL: " + redirectUrl);
}

/**
* Simple JSON key extractor without external libraries.
* Works for flat JSON responses like:
* { "token": "abc123" }
*/
private static String extractJsonValue(String json, String key) {
String pattern = """ + key + "":";
int index = json.indexOf(pattern);
if (index == -1) return null;

int start = json.indexOf(""", index + pattern.length()) + 1;
int end = json.indexOf(""", start);

if (start == 0 || end == -1) return null;

return json.substring(start, end);
}
}


Sample Response​

The API will generate a new Consent Request and return a response containing multiple attributes.

{
"crId": "0d2f6211-17f3-4e99-aec0-d6a0d404cfcd",
"createdAt": "2026-04-06T11:36:26.131734Z",
"dpHash": "68fb2ced2daaf430ebd5c9eb",
"fidId": "c8ab306d-0a53-4af1-9f3c-c4662df39500",
"noticeId": "c6808a21-3e86-4d9a-9de5-a849b427f5c6",
"noticeVersion": 3,
"redirectUrl": "https://staging.indiaconsent.com/consent?cr_id=0d2f6211-17f3-4e99-aec0-d6a0d404cfcd",
"requestId": "3c14b629-ae66-48f1-b5d7-cafc2078c1a4",
"serviceId": "shopping.order.fulfilment",
"status": "pending"
}

Important Response Attributes​

AttributeDescription
crIdUnique identifier of the Consent Request
requestIdRequest Reference ID
fidIdData Fiduciary identifier
dpHashHash representing the Data Principal context
statusCurrent state of consent request
serviceIdService ID of the consent (from the notice)
noticeIdThe consent notice shown to the Data Principal
noticeVersionThe notice version used: the one you asked for, or the current published version
redirectUrlURL to display the consent notice to the user

🚀 Most Important Field: redirectUrl​

The redirectUrl is the key output of this step.

This URL must be used by the Data Fiduciary’s UI to display the Consent Notice to the user.


What Happens Next?​

  • In Step 6, you will extract the redirectUrl from this response.

  • In Step 7, your application will open this URL to allow the user to Grant or Revoke consent.