Client Integration
Orchestrate journeys, offers, steps, and resume flows from your app.
In the API Experience, your app owns the borrower interface. The platform tells you what state the journey is in and what action is required next. Your client should treat returned status, nextAction, step actionRequired, and resource objects as the integration contract.
Minimal runtime sequence
- Ask your backend to create or resume a borrower session.
- Create a journey with
POST /api/v1/headless/journeysor resumeactiveJourney. - Read and update profile data through
GETandPUT /profile. - Submit profile through
POST /profile/submit. - Poll
GET /journeys/{journeyID}/stateor wait for webhook-backed backend updates. - Read offers and proceed with the selected offer.
- Render step resources from
GET /offers/{offerID}/steps. - Drive redirect flows such as AA consent, e-mandate, and loan agreement when returned as step resources.
Example client helpers
type Envelope<T> = {
requestID: string;
correlationID?: string | null;
timestamp: string;
data: T;
error: null;
};
async function apiFetch<T>(path: string, init: RequestInit = {}) {
const response = await fetch(`https://api.credit.aarthiklabs.com${path}`, {
...init,
headers: {
Authorization: `Bearer ${window.sessionToken}`,
"Content-Type": "application/json",
...init.headers,
},
});
const payload = (await response.json()) as
| Envelope<T>
| {
error: {
code: string;
message: string;
};
};
if (!response.ok) {
throw new Error(
"error" in payload ? payload.error.message : "Unexpected API failure.",
);
}
return (payload as Envelope<T>).data;
}
export async function createJourney() {
return apiFetch<{
journeyID: string;
status: string;
nextAction: string | null;
}>("/api/v1/headless/journeys", {
method: "POST",
headers: {
"Idempotency-Key": crypto.randomUUID(),
"X-Correlation-ID": crypto.randomUUID(),
},
body: JSON.stringify({
type: "PERSONAL_LOAN",
metadata: { source: "web_app" },
}),
});
}
export async function getJourneyState(journeyID: string) {
return apiFetch<{
journeyID: string;
status: string;
nextAction: string | null;
pendingOperations: string[];
updatedAt: string;
}>(`/api/v1/headless/journeys/${journeyID}/state`);
}Drive your UI from returned actions
Journey-level actions
FILL_PROFILE: show or resume the profile form.WAIT_FOR_OFFERS: move the borrower to an offer-waiting screen and poll state.VIEW_OFFERS: fetch and render offer cards.COMPLETE_AA: create or resume AA consent flow.COMPLETE_STEP: fetch the relevant step endpoint and render the returned resource.
Step-level actions
NONE: render completed state or continue automatically.SUBMIT_FORM: display the returned form fields and submit data to the matching step endpoint.REDIRECT: open the returnedredirectURLin the same app, browser tab, or native webview according to your UX.WAITorAWAIT_CALLBACK: show an in-progress screen and poll or wait for backend eventing.RECONCILE: call the matching reconcile endpoint after the borrower returns from an external redirect.
Resume behavior
Use the following APIs to restore the borrower journey cleanly:
POST /api/v1/headless/sessions: returnsactiveJourneywhen one already exists.GET /api/v1/headless/journeys: lists borrower journeys.GET /api/v1/headless/journeys/{journeyID}: returns full detail for a selected journey.PATCH /api/v1/headless/journeys/{journeyID}/resume: stores UI resume markers such aslastCompletedStepandlastViewedOfferID.
Offer selection
When the borrower selects an offer:
- Read offer detail from
GET /offers/{offerID}. - Show KFS, pricing, installments, and any AA indicators.
- Call
POST /offers/{offerID}/proceed. - Treat the returned
proceedBoundaryStateas authoritative.
Once an offer is locked, other offers for the same journey may no longer be valid for progression.
Step rendering guidance
- KYC: fetch
GET /steps/kycand render the current step status or the next lender-required action. - Bank mandate: fetch
GET /steps/bank-mandate; ifresource.type=FORM, render a form and submit throughPOST /steps/bank-mandate. - E-mandate: fetch
GET /steps/e-mandate; follow the redirect resource when present. - Loan agreement: fetch
GET /steps/loan-agreement; open or embed the returned agreement completion URL according to your UX policy. - Disbursal: use the aggregate steps response and journey state to know when the lender has moved beyond agreement signing into processing or disbursal.