Apple Device Check API: Missing or incorrectly formatted payload

We're trying to use Apple's device check API to send a device-validation request. I followed the document here https://developer.apple.com/documentation/devicecheck/accessing_and_modifying_per-device_data/#:~:text=Create%20the%20Payload%20for%20a%20Device%20Validation%20Request to format the request with required jwt header. we pass the device token in base64 encoded version as mentioned in documentation.

We get 400 Bad Request from the server with Missing or incorrectly formatted payload reason.
How can i resolve this error?

Thanks.
Apple Device Check API: Missing or incorrectly formatted payload
 
 
Q