How to read and save rest image/png response?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2019 04:37 AM
Hi everyone,
we have a service that response with a rest call with a qr code image png.
The image will be directly in the body without any json style ect.
How to use that byte array / image from rest to save it as an attachment on a record?
When logging it, it puts this:
�PNG
IHDRt ���IDATx^��A��0�ޠ��enPb{&����]��ɼ������c���(J���
��9��ߚ���}���,qٓ/�s֠~�yN~��Ρ��C�:X�.��@I]+Z��z�U�
\�|��j�,E�p��*~`���n�@� ���x9ؑ*¬���vp��z����p��=��H��I�T�@?�l�(�!J��(���]ȉ O(IEND�B`�
Best regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2019 06:04 AM
Can you share the raw REST payload (or a snippet of it)? These are almost always in text. That implies that the image is encoded (base64 perhaps) and needs to be decoded.
Let us know what you have tried already. Sharing code and results is most appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2019 07:18 AM
Hi Chuck,
thank you for your update. I know that that the rest reponse type is image/png type and the request body is a byte array. I found the saveResponseBodyAsAttachment function on RESTMessageV2 that works perfectly for me.
By the way, me and my team will be at the orlando conference and we would be pleased to have a coffee with you and a short chat.
Best Regards, and looking forward to Orlando conference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2020 01:15 AM
Hey I am facing the same issue. Can you help me with that please?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 08:27 AM
Hello all,
Last week I had the need to generate a QR code and save it as an attachment. When my returned data came back like this I knew I was close. After a couple of attempts at conversion I came across this Community post and it pointed me in the right direction (Thank you Chuck!) ... but not exactly.
Turns out there is an API for this specific use case.
saveResponseBodyAsAttachment(String tableName, String recordSysId, String fileName)
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_ws-namespace/c_RESTMessageV2API#r_RMV2-saveRespBodyAsAttach_S_S_S?navFilter=saveres
Here is an example of the code I used:
Hope this helps !!!