Using Batching With the Graph API Returns the Body Response As Base64 When Uploading a File

Shawn Bittinger 20 Reputation points
2023-08-25T12:37:33.8633333+00:00

I am attempting to use the Graph Batch API as defined here: https://learn.microsoft.com/en-us/graph/json-batching

Most request types return the response body in JSON format as show in the first request below. However any time I attempt to Upload a DriveItem using this API (https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http), I am seeing that the response body is returned as a base64 interpretation of the JSON response.

Is there any way to force the API to return this data in pure JSON format? I have attempted to leverage Accept headers with no success.

Note that when I call the Upload a DriveItem API outside of the batch request, it returns the body in JSON format without the base64 conversion as desired.User's image

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-08-28T05:59:34.77+00:00

    Hi,@Shawn Bittinger

    Thanks for letting us know your user experience. According to your case description, I do understand how frustrated you are now.

     

    When I received the case, I searched a lot of documents did a lot of researches. And I feel regretful to inform you that it turns out to be a by-design one.

    When using the Microsoft Graph Batch API, the behavior you're observing where the response body for uploading a DriveItem is returned as a Base64 encoded interpretation of the JSON response is expected and by design.

    This is a characteristic of how the Batch API handles file upload responses within batch requests.

    In a batch request, when you perform an action like uploading a DriveItem, the response content is base64-encoded due to the nature of how multipart batch responses are constructed.

    This encoding allows the binary response content (such as the uploaded file content) to be embedded within the overall batch response structure.

    Unfortunately, there isn't a way to directly control or force the API to return this specific type of response in pure JSON format within a batch response.

     

    And I noticed that some end users have also proposed the same request, it is highly recommended that you can vote this ticket. Many features of our current products are designed and upgraded based on customers’ feedback. With requirements like this increase, the problem may well be released in the future. Thanks for your understanding.

     

    feedback


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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