Is valid data for third party API
- To validate the request body of the third party API we should use the 'is-valid-data-for-third-party-api'.
- The API owner can set the request body schema store side in the 'API Details' tab within the 'reqBodySchema' object.
URL
/api/system-api/user-path/is-valid-data-for-third-party-api
Request payload
- Validate one third party API's request body.
| {
"apiBundleName": "bundle_name",
"apiVersionName": "api_version",
"name": "api_name",
"type": "BODY",
"data": {
"name": "Bob",
"mobile": 1234567890,
"married": true
}
}
|
- Validate multiple third party APIs request bodies.
| [
{
"apiBundleName": "bundle_name",
"apiVersionName": "api_version",
"name": "api_name",
"type": "BODY",
"data": {
"name": "Bob",
"mobile": 1234567890,
"married": true
}
},
{
"apiBundleName": "bundle_name",
"apiVersionName": "api_version",
"name": "api_name",
"type": "QUERY_PARAMS",
"data": {
"queryParam": {
"size": 123456
}
}
}
]
|
Validate third party request body
Test the data is valid for Third party API, using global object 'g'.
| await g.sys.system.isValidDataForThirdPartyAPI({
apiBundleName: "bundle_name",
apiVersionName: "api_version",
name: "api_name",
type: "BODY", // BODY | QUERY_PARAMS
data: {
name: 'hello'
},
isArray: false
});
|
API response
| {
"success": false,
"statusCode": 400,
"errors": [
{
"type": "required",
"field": "first_name",
"message": "Please provide valid 'first_name' field with type 'string'.",
"code": 400
},
{
"type": "required",
"field": "phone",
"message": "Please provide valid 'phone' field with type 'number'.",
"code": 400
}
]
}
|