Not able to upload contact picture via api

Hi all

I while ago I am sure I could upload a contacts picture using the following endpoint

/rest/v11/Contacts/{{ID}}/file/picture and send this as a post request.

I am now getting the following error pack from sugarcrm when I send a file with postman

Fullscreen
1
2
3
4
{
"error": "missing_parameter",
"error_message": "Incorrect field name for attachement: picture"
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Nothing has changed in my file upload code so does anyone know if the api has changed

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public static function postFile($module, $id, $filepath, $filename = '', $mime = '', $field = '')
{
self::connect_sugarcrm();
$field = (!$field) ? 'filename' : $field;
$url = "{$module}/{$id}/file/{$field}";
$file_arguments = array(
"format" => "sugar-html-json",
"delete_if_fails" => true,
"oauth_token" => self::$tokens->access_token,
);
$file_arguments[$field] = new CURLFILE($filepath, $mime, $filename);
$curl = curl_init(self::$SUGARENDPOINTURI.self::$API.$url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $file_arguments);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer",
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello 


    From your error message, it could be that you are adding an extra space/hidden character on the field name " picture" or "picture " instead of "picture".

    I could reproduce the same error in Postman when adding a space in the URL or in the key value. 





    Removing the empty space solved the error and I could upload the file without issues

    Could you double-check if this is what is happening in your scenario? 

  • Thank you @ it was my key-name in postman as you suggested a rouge space, just completely missed that so thank you