0

I sendes this batch request with postman:

POST /ucwa/oauth/v1/applications/105177669305/batch HTTP/1.1
Host: lync.myDomain.com
Accept: multipart/batching
Content-Type: multipart/batching;boundary=6555373f-c163-b72d-5c00-c3cc6cb9cd52
Authorization: Bearer cwt=AAEBHAEFAAAAAAAFFQAAAJFDb5_gw6wKmbRiI5oNABENAxu_zcjj9Rt7KWK3RkJSKCAvAPgyCThFvNa0lFTBPm5usuFxhbNo5VqemqSOoI-qWc_fihdoYI4G_bjjSS1AgNENAxu_zcjj9Rt7KWK3RkJSI
X-Requested-With: xmlhttprequest
Cache-Control: no-cache
Postman-Token: 57195c61-6b6f-0db9-5760-0af268fe7d55

--6555373f-c163-b72d-5c00-c3cc6cb9cd52
Content-Type:application/http;msgtype=request
GET /ucwa/oauth/v1/applications/10513269305/people/contacts HTTP/1.1
Host:lync.myDomain.com
Accept:application/json

--6555373f-c163-b72d-5c00-c3cc6cb9cd52
Content-Type:application/http;msgtype=request
GET /ucwa/oauth/v1/applications/10513269305/me/presence HTTP/1.1
Host:lync.myDomain.com
Accept:application/json

--6555373f-c163-b72d-5c00-c3cc6cb9cd52--

and got response status "400 Bad Request" with "Your request couldn't be completed." message. Did i missed some headers? If you know any reason why i get this error, please, tell me.

2 Answers2

0

From w3.org

HTTP Code 400 Bad Request means;

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

Check your request syntax. What kind of request format does your server expect? Would you be able to check server logs?

Tunceren
  • 754
  • 1
  • 8
  • 16
0

Lines need to end with Windows style line endings (\r\n), and should follow the format which is not even mentioned in the documentation

The following code is converted from batch.js in the UCWA samples, https://github.com/OfficeDev/skype-docs/blob/master/Skype/UCWA/samples/scripts/Batch.js

And the request limit in Batch is 100.

@Test
public void test() {
    List<String> parts = new ArrayList<>();
    String boundary = "77f2569d-c005-442b-b856-782305305e5f";

    for (int i = 0; i < 100; i++) {
        parts.add(createDataPart(boundary));
    }

    String data = parts.stream().collect(Collectors.joining("\r\n"));
    data += "\r\n\r\n--" + boundary + "--\r\n";

    try {
        HttpResponse<String> response =
            Unirest.post("https://lyncweb.example.com/ucwa/oauth/v1/applications/10820256145/batch")
            .header("authorization", "Bearer cwt=CCCCHAEFAAAAAAAFFQAAANz03DsuQ6xAB-U7K3yFAACBEBUTVWulRKhftCre06OKSveCAgghgyBAJ_THbZjk1M3ICsm1apTszG7HcKGll6HUDlc4i_fEEoYIU0vz-ojC1QgNEBDrIobFox9WpyA_EhuC5Mk")
            .header("content-type", "multipart/batching;boundary=" + boundary)
            .header("accept", "multipart/batching")
            .body(data)
            .asString();

        System.out.println("Response1 \r" + response.getBody());

    } catch (UnirestException e) {
        e.printStackTrace();
    }

}

String createDataPart(String boundary) {
    String dataPart = "\r\n--" + boundary;
    dataPart += "\r\nContent-Type: application/http; msgtype=request\r\n";
    dataPart += "\r\n" + "GET /ucwa/oauth/v1/applications/10820256145/people/test.user@example.com/presence HTTP/1.1";
    dataPart += "\r\n" + "Host: " + "lyncweb.example.com";
    dataPart += "\r\n" + "Accept: " + "application/json";

    //if (part.Data) {
    //    dataPart += "\r\n" + "Data: " + JSON.stringify(part.Data);
    //}
    dataPart += "\r\n";
    return dataPart;
}
Chuyu
  • 93
  • 1
  • 1
  • 6