1

I'm trying to retrieve contact with the below api call

CRM.api3('Contact', 'get', {
  "return": ["image_URL","first_name","last_name"]
}).done(function(result) {
  // do something
});

but my image url is always empty despite having an image on my contacts profile. This is what the response looks like

"is_error": 0,
"version": 3,
"count": 5,
"values": {
    "1": {
        "contact_id": "1",
        "image_URL": "",
        "first_name": "",
        "last_name": "",
        "contact_is_deleted": "0",
        "id": "1"
    },
    "2": {
        "contact_id": "2",
        "image_URL": "",
        "first_name": "AdminJoshua",
        "last_name": "AdminAroke",
        "contact_is_deleted": "0",
        "id": "2"
    },
    "3": {
        "contact_id": "3",
        "image_URL": "",
        "first_name": "Joshua",
        "last_name": "Aroke",
        "contact_is_deleted": "0",
        "id": "3"
    },
    "4": {
        "contact_id": "4",
        "image_URL": "",
        "first_name": "Oluwajuwon",
        "last_name": "Aroke",
        "contact_is_deleted": "0",
        "id": "4"
    },
    "5": {
        "contact_id": "5",
        "image_URL": "",
        "first_name": "Ogirima",
        "last_name": "Aroke",
        "contact_is_deleted": "0",
        "id": "5"
    }
}
}

I have been trying to put this to work. I'm using drupal 7 and I have profile image set on my contact. Please, let me know what to do right

5
  • 1
    Hi, Olyjosh, just tried this on the demo CiviCRM (4.7.17) instance and it works fine. I use the API explorer (See dmaster.demo.civicrm.org/civicrm/api#explorer). What is your version of CiviCRM? Does image_URL work when you call the API with the explorer or with Drush? Commented Feb 13, 2017 at 7:39
  • My version of CiviCRM is CiviCRM 4.7.16. The above json print is from the api explorer
    – olyjosh
    Commented Feb 13, 2017 at 23:10
  • Try to reproduce the situation on the demo instance. If it works, search for a difference on your local installation. Commented Feb 14, 2017 at 9:04
  • I just edited the demo instance and uploaded an image to the instance here http://dmaster.demo.civicrm.org/user/2/edit and I use the api explorer http://dmaster.demo.civicrm.org/civicrm/api#explorer to query drush like this drush cvapi Contact.get sequential=1 id=202. Behold, It's the same thing, the image element is empty too.
    – olyjosh
    Commented Feb 14, 2017 at 9:38
  • The image_URL returned by the API is the image that is attached to the CiviCRM contact, not to the drupal user. You can upload an image of a contact by selecting edit and upload a file with "Browse/Upload Image" in the first section. Commented Feb 14, 2017 at 9:58

3 Answers 3

1

The image_URL returned by the API is the image that is attached to the CiviCRM contact, not to the Drupal user. You can upload an image of a contact by selecting edit and upload a file with "Browse/Upload Image" in the first section.

0

This works (tested after attaching an image to a contact on the demo site):

CRM.api3('Contact', 'get', {
  "sequential": 1,
  "return": ["image_URL","first_name","last_name","email"],
  "image_URL": {"IS NOT NULL":1}
}).done(function(result) {
  // Debug first image URL retrieved:
  console.log(result.values[0].image_URL);
})
0

Following API call returned image_url

$result = civicrm_api3('Contact', 'get', array( 'return' => "image_URL", 'id' => CONTACT_ID, ));

Response looks like this:

{ "is_error": 0, "version": 3, "count": 1, "id": xxxxxx, "values": [ { "contact_id": "xxxxxx", "image_URL": "xxxxxxxxxxxxxxxxxxxxxx.com/civicrm/contact/imagefile?photo=Img1_ca0063c865d7fe65019be27dd071258c.png", "id": "xxxxxx" } ] }

Your Answer

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

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