Is it possible to post the API? Typically it's a byte array that you write to a file then display as you would normally display an image. As far as a reference number, if the API provider has some sort of unique id as part of the API, you can use that, otherwise you'd have to create your own. The api probably returns the image name and type so you should know what to name the file. I did a Webinar and Elevate 2019 presentation on Using DropBox with PowerBuilder that shows how to use the DropBox REST API to upload files, download files and view folder contents. You will probably find the download part helpful, images are one of the file types that I download. Here's links to the demo and also the code on CodeXchange. Good luck.
Kevin
https://www.youtube.com/watch?v=Qhola-1EJi8
https://community.appeon.com/index.php/codeexchange/powerbuilder/237-using-dropbox-rest-api-from-powerbuilder-code#307