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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

365 online webapi batch command response badrequest

(0) ShareShare
ReportReport
Posted on by

my content as below and the request return badrequest status:

POST https://xxxx.crm7.dynamics.com/api/data/v8.0/$batch HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjlGWERwYmZNRlQyU3ZRdVhoODQ2WVR3RUlCdyIsImtpZCI6IjlGWERwYmZNRlQyU3ZRdVhoODQ2WVR3RUlCdyJ9.eyJhdWQiOiJodHRwczovL3B0YmkuY3JtNy5keW5hbWljcy5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvY2ExNDczYmUtMWVlYS00NTU5LWIwYmEtZWE4NThlOTI5YmRmLyIsImlhdCI6MTQ5ODIwNzIyMiwibmJmIjoxNDk4MjA3MjIyLCJleHAiOjE0OTgyMTExMjIsImFjciI6IjEiLCJhaW8iOiJZMlpnWUdnelhpNldIN2o4ZTJCZTNBOE9mN2xsb3BkRG1BNVoyYTgvbERiSlUwK1Q2UzBBIiwiYW1yIjpbInB3ZCJdLCJhcHBpZCI6IjBkN2Q4NzFlLWY2ZjEtNDZiMi1iZjY0LThiM2YxYTUwODFlZSIsImFwcGlkYWNyIjoiMCIsImVfZXhwIjoyNjI4MDAsImZhbWlseV9uYW1lIjoi44K944OzIiwiZ2l2ZW5fbmFtZSI6IuOCqyIsImlwYWRkciI6IjEyNC43NC4xMDguMTU4IiwibmFtZSI6IuWtqyDkvbMiLCJvaWQiOiIwMWFiNTM0OC01ZTI3LTRiYzctYTA2YS04NzA0NGQ1NTlkODEiLCJvbnByZW1fc2lkIjoiUy0xLTUtMjEtMTk2NDMyMjU4Mi0yOTQyOTA1My05Njg5MTIwMzctMjAyOTEyIiwicGxhdGYiOiIzIiwicHVpZCI6IjEwMDMwMDAwQTE4RUQxQzAiLCJzY3AiOiJ1c2VyX2ltcGVyc29uYXRpb24iLCJzdWIiOiIyZFN0cVhWN2FaWFBjU1pyQUJNUi1pai1zWDlxeE56aDVrRmNIYU45dE9vIiwidGlkIjoiY2ExNDczYmUtMWVlYS00NTU5LWIwYmEtZWE4NThlOTI5YmRmIiwidW5pcXVlX25hbWUiOiJwdHowMDAwMDVAZ2ludHJhLWV4LmJjLWdsZXgubmV0IiwidXBuIjoicHR6MDAwMDA1QGdpbnRyYS1leC5iYy1nbGV4Lm5ldCIsInZlciI6IjEuMCJ9.GD6VFY6mp-rvrx4hjO22oo0m0rLtMn_1zmyAKKoiIepQn5aJYf_MTU6Qn8ZJ-sf19oJuC7y16csQyksElsr39TaQRYZJiyNZXxZB-sMREOOuDlKptUU-2I3CGguJ7_0VmClP4aVaIlnWrgDLR2j-5F00utD80lItnyM4Ao7xlyup49b6un1T9sOuH7b4zuApPonJIjM38PXw-Yw3a1L6C901FVGqaDQT5MzjOkBTj_6_q0fiMYKICOuexLVd_5EYghMadP5M2N6dYBURk2jPhs6g23UzeegdqvDBeXYllDO0bSEpxCNA1galtFj9LW2Sv1-XBqSKlYK4Hb5bquV8WQ
Content-Type: multipart/mixed; boundary="batch_32d0d46d-8cb5-4777-bfdf-cc1476579f3f"
Host: ptbi.crm7.dynamics.com
Content-Length: 1062
Expect: 100-continue

--batch_32d0d46d-8cb5-4777-bfdf-cc1476579f3f
Content-Type: multipart/mixed; boundary="changeset_1614cd2e-76af-45b7-8d9b-0ee0f3263720"

--changeset_1614cd2e-76af-45b7-8d9b-0ee0f3263720
Content-Type: application/http; msgtype=request
Content-Transfer-Encoding: binary
Content-ID: 1

PATCH /api/data/v8.0/new_onetimepasses(new_name='FxUD6q6y',new_onetimepassnumber='36017000059') HTTP/1.1
Host: xxxx.crm7.dynamics.com
Content-Type: application/json; charset=utf-8

{
  "new_name": "FxUD6q6y",
  "new_onetimepassnumber": "36017000059"
}
--changeset_1614cd2e-76af-45b7-8d9b-0ee0f3263720
Content-Type: application/http; msgtype=request
Content-Transfer-Encoding: binary
Content-ID: 2

PATCH /api/data/v8.0/new_onetimepasses(new_name='HUQI1y4u',new_onetimepassnumber='36017000051') HTTP/1.1
Host: xxxx.crm7.dynamics.com
Content-Type: application/json; charset=utf-8

{
  "new_name": "HUQI1y4u",
  "new_onetimepassnumber": "36017000051"
}
--changeset_1614cd2e-76af-45b7-8d9b-0ee0f3263720--

--batch_32d0d46d-8cb5-4777-bfdf-cc1476579f3f--

what is the key error in this content?  did microsoft provide c# demo regarding to the webapi batch?

My code:

            var onetimepassUpdate1 = new JObject();

            onetimepassUpdate1.Add("new_name", "FxUD6q6y");

            onetimepassUpdate1.Add("new_onetimepassnumber", "36017000059");

 

            var onetimepassUpdate2 = new JObject();

            onetimepassUpdate2.Add("new_name", "HUQI1y4u");

            onetimepassUpdate2.Add("new_onetimepassnumber", "36017000051");

 

            var request1 = new HttpRequestMessage(new HttpMethod("PATCH"), "https://xxxx.crm7.dynamics.com/api/data/" + getVersionedWebAPIPath() + "new_onetimepasses(new_name='FxUD6q6y',new_onetimepassnumber='36017000059')");

            request1.Content = new StringContent(onetimepassUpdate1.ToString(), Encoding.UTF8, "application/json");

 

            var request2 = new HttpRequestMessage(new HttpMethod("PATCH"), "https://xxxx.crm7.dynamics.com/api/data/" + getVersionedWebAPIPath() + "new_onetimepasses(new_name='HUQI1y4u',new_onetimepassnumber='36017000051')");

            request2.Content = new StringContent(onetimepassUpdate2.ToString(), Encoding.UTF8, "application/json");

 

            var batchRequest = new HttpRequestMessage(new HttpMethod("POST"), getVersionedWebAPIPath() + "$batch");

            var content_batch = new MultipartContent("mixed", "batch_" + Guid.NewGuid().ToString());

 

            var content_changeset = new MultipartContent("mixed", "changeset_" + Guid.NewGuid().ToString());

            var mc1 = new HttpMessageContent(request1);

            var mc2 = new HttpMessageContent(request2);

            mc1.Headers.Add("Content-Transfer-Encoding", "binary");

            mc1.Headers.Add("Content-ID", "1");

            mc2.Headers.Add("Content-Transfer-Encoding", "binary");

            mc2.Headers.Add("Content-ID", "2");

            content_changeset.Add(mc1);

            content_changeset.Add(mc2);

 

            content_batch.Add(content_changeset);

            batchRequest.Content = content_batch;

            //var xs = await content_batch.ReadAsStringAsync();

            var batchResponse = await httpClient.SendAsync(batchRequest);

            var x = batchResponse.StatusCode;

            Console.Write(x.ToString());

*This post is locked for comments

I have the same question (0)

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans