Posting Zip files with HTTP Request

Hi,
I am currently working on a process where we use Data Management Rest APIs for uploads to Microsoft Dynamics. We have managed to build a working POST request with Postman, see the screenshots below:

Postman - Body:

Postman - Headers

However, when I try to recreate this using the UiPath HTTP Request activities it seems like the attached file is ignored, the behaviour from Dynamics is the same as if I use the Postman Request but remove the input data file. This API always responds with a 200 status code and a Message ID upon authenticated requests, the difference is only noticed in Dynamics where the data is uploaded. See UiPath Screenshots for the HTTP Request below:

UiPath Http Request Properties:

Attachments:
image

Headers
image

Parameters
image

UrlSegments
image

What can I do to accurately recreate what Postman does with the file contents by using the HTTP Request activity?

Found a solution! Added the RestSharp package and made the following Invoke Code activity with the following code:

var client = new RestSharp.RestClient(postEndpoint);
client.Timeout = -1;
var request = new RestSharp.RestRequest(RestSharp.Method.POST);
request.AddHeader("Authorization", String.Concat("Bearer", bearerToken));
request.AddHeader("Content-Type", "application/zip");
request.AddParameter("application/zip", System.IO.File.ReadAllBytes(filePath), RestSharp.ParameterType.RequestBody);
RestSharp.IRestResponse response = client.Execute(request);
2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.