How to pass .csr certificates in rest API request body

I need to pass .csr certificate as an input for my request body. This certificate is generated through shell script and it needs to be passed as a parameter to my request body.
It works fine if I hardcode this value, but if this is given as a parameter my request is getting failed. It says invalid csr. Looks like there’s an issue with formatting the string when given as parameter.

My certificate looks something like this:
var cert = “-----BEGIN CERTIFICATE REQUEST-----\nMIICdDCCAVwCAQAwLzEtMCsGA1UEAwwkMGFjNDA2NTktMzczMC00ZGJjLTg0MmIt\nYzA2MGExZTY4OTE3MIIBIjANBgkqhkiG9w0BAAOCAQ8AMIIBCgKCAQEAs5tA\naTVoX3NmlbM4XSshaC0qF445aFEbxh613YRJMFXtTD07Qh1u+bTb16uuMDjwAl1s\nBYO6sMFLTuA10fIu1XomOFJ9NehvdjYZKNka9KwYGa3dBTvnOMy3QDCrvADm\nRe5VAh3mWYyDI5ypZ7IBtOm2I0dBVjTzONs3jhbbJYjo8nZn8zILjFBRRvfPjIJE\nWNwbV+y+dS5AEExxbBVB0jXg6r88OZkBwxWsjSqGfDWkdtujcuAz37WO5QNNh7xg\nvhd5EGJhO5VaukIM5rYDBGZNHlg5u/cDTYoYv5iri/FNVVK02bAIYRQpxeCX\n0MmceQZ5nS3L2W1xpQIDAQABDQYJKoZIhvcBgEBACjoSKxetOqD\nBIoMTNcxhcTmsq3jCRUH83Xyt98kz5VNz6gRLjOjW0A68Q6HJEs28TBSMSvbk\nes72GdqxGenrGWnH1q8I+1zT1Xaa+CjQSWEEMzWyJBbZpbVGzsqgP+yAJ2lfDe9Q\nHiPgGjxyY2WtA0LXBi0jRk37jate7BSlsJzX5RNnw7YHmgnIbb/rBbZSWJ8OO00y\n9P8eiYUj13vL66geNzBlZnGuZ/dFB5IekKXA+BwbcenWQyHqp8M5PRiZsDke\nYFRf43qE+G4vg7FisjuQB8YBRdo9aQjXEk0UveoYetvVd69IZ0F91jDUvY29VXMl\nwiqGsed6TTs=\n-----END CERTIFICATE REQUEST-----\n”

My request body looks like below.

I.sendPostRequest(‘reqURL’, {
“csr”: cert
});

Any suggestions on how to handle this?

Did you compare the content of the cert parameter and the hard coded value? What does cert say?