Bulk Import API: Malformed Multipart Body Error

3 1 0


I have followed the below link for bulk import. 




I have written an Azure service for creating/updating products by following the above link. It was working fine for a good 11 months as it was using AWS to upload the file. 


However, Shopify has changed the bulk import technique from AWS to Google. This is where the problem starts. 

I am getting the following error message. 


"Malformed multipart body."  


Please see the code snippet that I am using. 


var headers = new[]
                    new KeyValuePair<string, string>("key", stagedTargets?.Parameters.FirstOrDefault(x => x.Name=="key")?.Value),
                    new KeyValuePair<string, string>("x-goog-credential", stagedTargets?.Parameters.FirstOrDefault(x => x.Name=="x-goog-credential")?.Value),
                    new KeyValuePair<string, string>("x-goog-algorithm", stagedTargets?.Parameters.FirstOrDefault(x => x.Name=="x-goog-algorithm")?.Value),
                    new KeyValuePair<string, string>("x-goog-date", stagedTargets?.Parameters.FirstOrDefault(x => x.Name=="x-goog-date")?.Value),
                    new KeyValuePair<string, string>("x-goog-signature", stagedTargets?.Parameters.FirstOrDefault(x => x.Name=="x-goog-signature")?.Value),
                    new KeyValuePair<string, string>("policy", stagedTargets?.Parameters.FirstOrDefault(x => x.Name=="policy")?.Value),
                    new KeyValuePair<string, string>("acl", "private"),
                    new KeyValuePair<string, string>("Content-Type", "text/jsonl"),
                    new KeyValuePair<string, string>("success_action_status", "201"),

                using var multipartFormDataContent = new MultipartFormDataContent();

                foreach (var (key, value) in headers)
                    multipartFormDataContent.Add(new StringContent(value), key);

                await using (var memoryStream = new MemoryStream())
                    await stream.CopyToAsync(memoryStream);
                    var byteArray = memoryStream.ToArray();

                   multipartFormDataContent.Add(new ByteArrayContent(byteArray, 0, byteArray.Length), "file", "products_long");

                var responseMessage = await httpClient.PostAsync(requestUrl, multipartFormDataContent);


Could someone please let me know what exactly I have to do to fix this issue? Thanks in advance. 


Replies 0 (0)