function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
h0llyh0lly 

place order / bad request

I am trying to programmatically create an order using REST API (.net c#)

I have tried:
1. Add an Order to an existing A/C : /services/data/v30.0/commerce/sale/order
2. Add Order Products to an Existing Order: /services/data/v30.0/commerce/sale/order/[Order Ref]

In both attempts I get a Bad Request (400).

If I take Option 1 above as an example.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string uri5 = "https://[salesforce app url/services/data/v30.0/commerce/sale/order";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri5);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization", "OAuth " + token);
httpWebRequest.Headers.Add("Authorization", "Bearer " + token);
httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
     string jsonnew = "";
     //build the json as described in 
     https://developer.salesforce.com/docs/atlas.en-us.api_placeorder.meta/api_placeorder/sforce_placeorder_rest_api_place_order_account.htm

     streamWriter.Write(json);
     streamWriter.Flush();
     streamWriter.Close();
}

using (var myResponse = httpWebRequest.GetResponse() as HttpWebResponse)
{
  if (httpWebRequest.HaveResponse && myResponse != null)
  {
     using (var streamReader = new StreamReader(myResponse.GetResponseStream()))
     {
        ....do stuff here
     }
  }
}