How to store byte into bytearray

now_dev
Mega Expert

Hi All,

I am trying to retrieve a certificate from third party and in response I am getting certificate bytes. How do I store certificate byte in an array and then finally write to file?

Request

POST https://abc.example/abcd/certificates/Retrieve

X-Api-Key: 7cd2319e-5b50-4fe1-a3b6-d40c5fe1d156

{

"CertificateDN": "\\VED\\Policy\\www.abc.com",

"Format": "Base64"

}

Response

HTTP/1.1 200 OK

{

"CertificateData":"LS0tLS1CRUdLS0tLS0NCg==",

"Filename":"www.venafi.com.cer",

"Format":"Base64"

}

I wanted to convert my certificate data in below format. Please suggest.

"-----BEGIN CERTIFICATE REQUEST-----

MIIDGzCCAgMCAQAwXTEXMBUGCgmSJomT8ixkARkWB2V4YW1wbGU/ WPlT2R3xw

98+dnGb7yvMaIxDWB5pdlb43pQxdxS0tZgVcClE6fDKCg5+bdffacA==

-----END CERTIFICATE REQUEST-----"

3 REPLIES 3

dj21
Giga Expert

the response format is already in Base64, So a file can be written to ecc queue.


Below code snippet is one example I used to attach an excel file to a transaction rec(INC/CHG etc)


Do you store the generated files in SNOW table?


AttachmentCreator.jpg


Hi dj2,



Yes I am saving the response in a custom table. The end goal is to allow user to download this certificate on his/her machine.



Can you please suggest a approach.


You could use the code snippet i shared. you can pass the response data(base64) form the third party as ecc "payload".


ecc.source should be a record(sys_id) from your custom table.


ecc.name - this is the name of the certificate file which will be added to the source records as an attachment (please specify the file extension ex. filename.xls)- to uniquely identify you may use the source table record identifier


(When certification file types are opened/ saved from from, Im not very sure how Service now handles the file types- please try and let me know)