Skip to content

Error in getting image from Graph API in spring-boot with resttemplate

I am using the graph api:

GET /users/{id | userPrincipalName}/photo/$value

to get the particular user’s profile photo with my access token. In postman I am able to see the image using the above get call. In my spring-boot application I am using like below:

final ResponseEntity<Object> profilePicture =, HttpMethod.GET, new HttpEntity<>((header)), new ParameterizedTypeReference<>() {});

I am getting below error:

Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [image/jpeg]

I have defined RestTemplate like:

    public RestTemplate restTemplate() {
        return new RestTemplate();

Could someone please help me with this?



You need to add an appropriate MessageConverter to your RestTemplate.

Something like:

 RestTemplate restTemplate = new RestTemplate();
 restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
 ResponseEntity<byte[]> response =, 
 HttpMethod.GET, new HttpEntity<>((header)), byte[].class);

You can read more on this subject here:

10 People found this is helpful