Skip to main content
This page explains how to perform Turkish ID number validation in JSON format using Groovy script policy. This groovy code first checks the character length of the Turkish ID number. If appropriate, it validates the Turkish ID number with a specific algorithm. These validation steps involve certain mathematical calculations of the Turkish ID number. In case of any error, an appropriate error message is assigned to the requestErrorMessageToTargetAPI variable and the request is prevented from going to the backend.

Groovy Script

Sample Request

Explanation

This script performs the following operations:
  1. Parsing JSON: Parses the incoming request body using JsonSlurper.
  2. Extracting Turkish ID Numbers: Extracts requestingUserIdentityCardNo and requestedIdentityCardNo fields from JSON.
  3. Validation: For each Turkish ID number:
    • Length check (must be 11 characters)
    • Mathematical algorithm validation (checking 9th and 10th digits)
  4. Error Management: If validation fails, an error message is assigned to the requestErrorMessageToTargetAPI variable and the request is not sent to the backend.
This script should be run on the request line (Request Policy) because it uses the requestBodyTextFromClient variable.