web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

The remote server returned an error: (400) Bad Request.

(0) ShareShare
ReportReport
Posted on by 384

Dears,

using the api integration, i am trying to insert a new product on shopify using the below code but it's giving this error The remote server returned an error: (400) Bad Request  while getting the response

 public static void main(Args args)
    {
        System.IO.Stream        requestStream;
        str url = "https://xxxx.myshopify.com/admin/api/2021-01/products.json";
         str user = "xxxxxxxxxx";
        str pass = "xxxxxxxxxxxxx";
        str token,rawresponse;
        List mylist = new List(Types::String);
        mylist.addend("Barnes & Noble");
        mylist.addend("Johns Fav");
        mylist.addend("Big Air");
        IS_ShopifyContract contract  = new IS_ShopifyContract();
        contract.ParmTitle('test 123');
        contract.Parmbody_html('This is a test product');
        contract.ParmVendor('abc');
        contract.ParmProduct_type('Snowboard');
        contract.ParmTags(mylist);
       
        System.Text.Encoding encoding = System.Text.Encoding::UTF8;
        System.Byte[] bytes = encoding.GetBytes(user   ":"   pass);
        System.String base64 = System.Convert::ToBase64String(bytes);
        var  utf8    = System.Text.Encoding::get_UTF8();
        str json = FormJsonSerializer::serializeClass(contract);
        var bytes1 = utf8.GetBytes(json);
        System.String headerKey = 'Authorization';
        System.String headerValue = 'Basic '   base64;
        System.Net.WebRequest request = System.Net.WebRequest::Create(url);
        System.Net.WebHeaderCollection headers = request.Headers;
        headers.Add(headerKey,headerValue);
        request.set_method('POST');
        request.ContentType='application/json';

        requestStream = request.GetRequestStream();
        requestStream.Write(bytes1, 0, bytes1.get_Length());

        System.Net.WebResponse response = request.GetResponse();
        
        System.IO.StreamReader reader = new System.IO.StreamReader(
            response.GetResponseStream());
        str wsResponse = reader.Readtoend();
        
        info(wsResponse);
    }

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    This problem might not have much to do with Dynamics.

    However, regardless of the technology that you use to create the request, you should debug your code to see the request. Then compare it to Shopify documentation that describes the request format.

    You can also use PostMan to try to first manually create a correct request - and only then write code to create a similar request.

  • sylvesterPowerBi Profile Picture
    384 on at

    hi Nikolaos,

    using postman i was able to create the product, im thinking it might be an issue with app admin created on shopify.

    the code is running well but it's giving the error here

    System.Net.WebResponse response = request.GetResponse();

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Unfortunately there isn't much we can do for you here. You should look for a forum about the Shopify API.

  • Suggested answer
    yersah Profile Picture
    12 on at

    Which line you are getting this error. From error its souns like 36 but I dont see any error your code. Can you share json.

    You can try send as a string;

    streamWriter = new System.IO.StreamWriter(request.GetRequestStream());
    streamWriter.Write(jsonstr);
    streamWriter.Flush();
    streamWriter.Close();

    Are you sure about UTF-8, maybe you can try ISO-8859-1

    You can try create json not as contract class but as a plain string (just copy string from myshopify's document)

    Lastly Postman has a code creater which is using restSharp. You can try with the successful code (with resSharp dll)

  • Suggested answer
    sylvesterPowerBi Profile Picture
    384 on at

    i managed to fix it by adding a new contract class :product" that takes parameter the shopify contract class

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 540 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans