finished javascript for api call for image