Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Bulk Import API: Malformed Multipart Body Error

Bulk Import API: Malformed Multipart Body Error

excellentpick
Shopify Partner
4 1 0

Hello, 

I have followed the below link for bulk import. 

 

https://shopify.dev/api/usage/bulk-operations/imports

 

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)