Recent searches


No recent searches

Attempting to set user profile photo via API is failing



Posted Jul 07, 2022

I am attempting to set the user profile photo via the API.  I am able to add and update users, but I am having issues with adding the photo.

I am getting the following error returned in the headers:

x-zendesk-api-warn, val={:allowed_parameters=>{:controller=>"users", :action=>"update", :unpermitted_keys=>["user.photo.content_url"], :invalid_values=>[]}}

  I am sending the following JSON:

{
  "user": {
    "photo": {
      "content_url": "https://apex.cct.rpi.edu/apex/simon_apex.display_blob?URL_KEY=GHu5iY48fMQC6ExnuardXOLNd"
    },
    "id": 7412860633620,
    "external_id": "91000000",
    "name": "Jon Finke",
    "email": "finkej@rpi.edu",
    "verified": true,
    "user_fields": {
      "display_name": "Jon Finke",
      "first_name": "Jon",
      "last_name": "Finke",
      "rcs_id": "finkej",
      "portfolio": "Division of the Chief Information Officer (DotCIO)",
      "department": "Database Administration"
    }
  }
}


1

10

10 comments

Hi John, 
I had this same issue a year ago. Support was never able to fix it and told me that it was not a priority and to just re-run the API commands again and again until I got the desired result. :\ 

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Jon,
 
I tested this out using the image you provided and had a similar result. When looking at logs, your server is responding back to the request with "No more references allowed". Is there a way for your image provider to add your Zendesk instance to a whitelist? This may assist with that issue. 
 
@CJ 
 
I'd be interested in taking a look at that ticket number if you have it. 
 

0


The URL provided had a limited lifetime and use count - it had hit the max of 5. I kicked it up to 50.

0


In checking the web server logs, I am not seeing any hits from Zendesk servers, so I am guessing that my API update was NOT making it in.

I was just hoping that passing a URL to the Zendesk API would be a quick way to get photos imported to our Zendesk instances.  I am open to other alternatives - the API documentation referenced the Attachment API (IIRC), but that claimed it was limited to attachments for tickets.

 

0


Eric Nelson Sure thing - #9678190.  

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Jon,

If you want to just pass in the URL have you thought about using the remote_photo_url parameter instead? You'll need to keep the photos accessible on your server, but otherwise that'd be a simpler way of going about it.  

0


I tried passing in the URL into the remote_photo_url - and that works - the photo appears on the user profile page as desired.  But I would rather not leave that URL "live" - it is intended for short term, secure access.  Checking my web server logs, it appears that the value is being cached somewhere, which is good - only one hit to my web server (this is good).  On the other hand, the reference is from a generic AWS server, so I can't "white list" the host.

I was able to load a photo as an attachment (as suggested in the "Users" part of the API documents, but I was unable to figure out how to associate the uploaded "attachment" with the user entry.

Just adding a "photo" element with the token resulted in a

x-zendesk-api-warn, val={:allowed_parameters=>{:controller=>"users", :action=>"update", :unpermitted_keys=>[], :invalid_values=>["user.photo"]}}

 

0


Progress of sorts - still doesn't work though.

I am able to load the photo via the "uploads" process, and get a token and access URLs (which allowed me to confirm that Zendesk indeeds HAS the photo I uploaded).  My latest attempt to attach the photo to a user (agent) record, 

https://rpi-registrar.zendesk.com/api/v2/users/7412860633620.json?token=vQcGDNGc9jFJM4CEkW3yOtbWv

With the body

{"user":{"id":7412860633620,"photo":{"uploads":["vQcGDNGc9jFJM4CEkW3yOtbWv"]}}}

Resulted in a status code of 200 and the following:

x-zendesk-api-warn, val={:allowed_parameters=>{:controller=>"users", :action=>"update", :unpermitted_keys=>["user.photo.uploads", "token"], :invalid_values=>[]}}

 

The dreaded unpermitted keys error. 

Can the uploaded/attachment followed by using the token to set the value work for a user record? Does anyone have working example?

Do we need to have a setting changed somewhere to allow this to happen via the API?

 

0


image avatar

Christopher Kennedy

Zendesk Developer Advocacy

Hi Jon,
 
Can you share which API endpoint you used to upload the file?

0


Not sure if this will be helpful for your case or not but I have been doing this successfully by only passing the string 'remote_photo_url' instead of doing anything with the photo object itself e.g.

{
"user": {
"remote_photo_url": "https://example.com/example/path/image.png"
}
}

The response body will not include the photo, but a subsequent GET will show the details-- I assume collecting the data from the url specified and writing the photo object, etc. is done asynchronously.

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post