- Clarity: the schema defines every requirement programmatically, including required fields, data types, formats, and structures. This eliminates guesswork.
- Client-side validation: OFIs can validate their response against the schema before making the API call, providing instant feedback for developers and preventing common integration errors.
- Rich data structures: schemas support complex requirements like nested address objects and conditional logic.
Interpreting JSON Schema
When you call the get details for an RFI endpoint, the API returns the JSON Schema for the required response data. The following are key parts of the schemas to understand when reading them:properties: defines the fields you can provide in your JSON responserequired: contains a list of field names that must be present in the response$defsand$ref: usable complex objects (defined in$defsand referenced using the$refdirective)
Client-side validation
JSON Schema allows you to validate your response before sending it to the API. CPN expects that OFIs perform client-side validation against the provided schema before submitting a response to CPN. Doing so provides a first line of defense to reduce API errors and failed payments. Common libraries for JSON Schema validation are:- Java: networknt/json-schema-validator
- Python: jsonschema
- Node.js: ajv