Unable to subscribe web-hook for SharePoint online

Viewed 205

We are unable to subscribe web-hook for SharePoint online from our Spring-Boot application.

Providing valid notification URL(https enabled, publicly accessible, valid domain name, Post method) as parameter while consuming rest API in order to subscribe web-hook.

    @PostMapping(value = "/spnotification")
    @ResponseBody
    public ResponseEntity<String> handleSPValidation(@RequestParam final String validationtoken) {
        LOG.info("validationToken : " + validationtoken);
        return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN)
                .body(validationtoken);
    }

And on this notification URL end-point, we are able to receive validation string from share-point as parameter and same string we are retiring in less then 5 sec with content-type text/plain and http status code 200 as response.

still getting 400 bad request with below error message.

400 Bad Request: [{"error":{"code":"-1, System.InvalidOperationException","message":{"lang":"en-US","value":"Failed to validate the notification URL 'https://example.com/notification-listener-service/api/webhook/spnotification'."}}}]

Note : We are following this API documentation to subscribe web-hook.

We tried Graph API also for the same purpose but in that case getting below error.

"error": {
        "code": "InvalidRequest",
        "message": "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF"
       
    }

Please find this diagram for more understanding on this issue.

enter image description here

We really appreciate if someone can help us on the same.

1 Answers

Please check the @PostMapping(value = "/notification", headers = { "content-type=text/plain" }) enter image description here

@PostMapping(value = "/notification", headers = { "content-type=text/plain" }) 
@ResponseBody
    public ResponseEntity<String> handleSPValidation(@RequestParam final String validationtoken) {
        LOG.info("validationToken : " + validationtoken);
        return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN)
                .body(validationtoken);
    }

GitHub Code

Related