Failure while trying to download an image from a teams message using Microsoft teams graph API connector in Logic Apps

Puneet Jain 20 Reputation points Microsoft Employee
2024-09-30T08:02:12.23+00:00

I am trying to download an image from a teams message using the Send a Microsoft Graph HTTP request action in Microsoft Teams connector in Logic Apps. From a URl of type this:

https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages/{message-id}/hostedContents/{content-id}/$value

With ContentType: image/png

Here is the error I am getting while making the request:

BadRequest
Http request failed as the content was not valid: 'Unable to translate bytes [89] at index 0 from specified code page to Unicode.'.

Can you help suggest how this can be rectified? The graph connector has the necessary permissions for this call, hence I want to utilize the same. Do let me know if there is a workaround.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
Microsoft Teams | Development
Microsoft Teams | Development
Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs
Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Sonny Gillissen 3,996 Reputation points Volunteer Moderator
    2025-03-31T21:07:16.46+00:00

    Hi Puneet Jain

    Thanks for reaching out on Microsoft Q&A!

    Seems like the API is returning a response as binary, decoded, where logic apps wants a binary to be displayed as BASE64, thus throwing strange errors. I’ve had the same issue when calling the SharePoint CSOM API to retrieve a list attachment’s content.

    There is no way to do this in a Logic App before the API is fixed, however you can add an API Management Service in between in the mean time to convert the response of the API to a byte array which makes the logic app interpret the file as it should.

    By adding the snippet below to your APIM policy you should be able to get the contents properly:

    <policies>

    <inbound>

    <base />

    <set-backend-service base-url="https://graph.microsoft.com/v1.0" />

    <rewrite-uri template="/teams/{team-id}/channels/{channel-id}/messages/{message-id}/hostedContents/{content-id}/$value" copy-unmatched-params="false" />

    </inbound>

    <backend>

    <base />

    </backend>

    <outbound>

    <!-- Don't use the base as we don't want encoding to json -->

    <!--<base />-->

    <!-- Set value response as byte array -->

    <set-body>@{

    return context.Response.Body.As<Byte[]>();

    }</set-body>

    <!-- Set necessary headers -->

    <set-header name="Content-Disposition" exists-action="delete" />

    <set-header name="Content-Transfer-Encoding" exists-action="override">

    <value>base64</value>

    </set-header>

    </outbound>

    <on-error>

    <base />

    </on-error>

    </policies>

    Please click ‘Accept answer’ if you think my answer is helpful. Feel free to drop additional queries in the comments below!

    Kind regards,

    Sonny


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.