2

How can I retrieve images uploaded in custom field sets for contacts? Could you get a URL for them the same way you can for the contact "image_url" in the API?

When I look up the custom field for the file in the API, it just returns a number. I looked at the code docs for the Attachment entity in the API, but this seems to be more suited for non-image files, unless I'm mistaken. I am looking to call the API and display these images on a web page.

I'd appreciate any help I can get, thanks.

1 Answer 1

2

Without more context about what the API call you're making is, I can't say why it just returns a number. Here's what happens when I call the API from my command line to get the results of the attachment with an ID of 1:

» cv api attachment.get id=1
{
    "is_error": 0,
    "version": 3,
    "count": 1,
    "id": 1,
    "values": {
        "1": {
            "id": "1",
            "name": "Project_Properties_dmaster_677.png",
            "mime_type": "image/png",
            "description": "",
            "upload_date": "2018-11-27 22:19:47",
            "entity_table": "civicrm_activity",
            "entity_id": "628",
            "icon": "fa-file-image-o",
            "created_id": "",
            "url": "http://dmaster.localhost/civicrm/file?reset=1&id=1&eid=628",
            "path": "/home/jon/local/civicrm-buildkit/build/dmaster/sites/default/files/civicrm/custom//Project_Properties_dmaster_677_ab277eebda5f50aeb9910018ab356f34.png"
        }
    }
}

It returns the URL property which I can output in an HTML file within an <img> tag to display the image on a web page.

1
  • Sorry for not clarifying in the original post. After more research I realized that the number I was referring to is the file ID number that shows up as a field when getting a contact's info. Thanks for the help.
    – Blake
    Nov 28, 2018 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.