Not Able to create Subscription to mailbox using Microsoft graph API - java

Getting Subscription validation failed.Must respond with 200 OK error
I was trying to create a subscription using Microsoft graph API. We have exposed a notification URL which on receiving the post-call from the graph API will respond with the validation token and also status code: 200 OK.
When I tried hitting the subscription API for creating subscription it is showing "Getting Subscription validation failed. Must respond with 200 OK"-error. And At the same time, we are getting Status: 400 Bad request in postman.

Microsoft Graph validates the notification endpoint provided in the notificationUrl property of the subscription request before creating the subscription.
If validation fails, the request to create the subscription returns a 400 Bad Request error.
Please make sure that you provide a valid notificationUrl in the body. See Notification endpoint validation to see how Microsoft Graph handles the validation process.

Related

How can we perform 2 get request at same time Rest assured API Testing

JAVA RESTASSURED APITESTNG CUCUMBER
when I send get request using path variable and query param, I get a token in the response body and I will not get proper response until I add that token as a query param and send another get request.
So How can I perform that?
Given Cucumber Feature File
Given API has the following filed <"fieldName">
When API sends a "GET" request to "TranscationAPI"
Then API will receive the response code as 200
And the body will have following field
Should I change it to something like this?
Given API has the following filed <"fieldName">
When API sends a "GET" request to "TranscationAPI"
Then API will receive token as ""
When API sends again "GET" request to "TranscationAPI"
Then API will receive the response code as 200
And the body will have following field
Or I can use handle this through a different method.
Background is the great place to obtain token - see https://cucumber.io/docs/gherkin/reference/#background
It's possible by Java multithreading mechanism - https://www.tutorialspoint.com/java/java_multithreading.htm

In case of an exception in webservice is the control returned to to UI with error?

I have a UI page developed using angular js and make a rest webservice call. If an exception is thrown by webservice will the control be returned to the UI with the error?
yes, it will be returned to the client. This is true even if the server timesouts.
But it might not be in a format as you expected. For example, you might have sent a json request and expecting a json response. But you might get an html response if the server has setup a simple html handler for error code. In this case your response parsing will fail. One common example is the authentication failure, which simply redirects you to html login page in many services.
So before parsing the result, check the status code. Check the service rest api docs and study the error handling semantics. Then parse the error accordingly.

How to read websocket response code through automation scripts

Suppose I have a resource that is hosted on a websocket server, and I wish to validate the response status code 101, after the connection is upgraded, how and which libraries to use.
Im currently looking at jayway response library, when I connect to a websocket resource, initially it sends a 200 and then upgrades to 101. So code returns 200, I would like to know how this library can be used for websocket validation.
Sample code is :
String response =given().get()("https://www.ws.com:444/examples/websocket/snake.xhtml")
.getResponse().asString();
This returns a 200, but does not return the next response. I might sound a little rusty here, would appreciate if you folks have any idea how to extend it to get status 101 or if you have any other suggestions.
Also, this requirement needs to be extended to handle redirection 30x status codes as well, assume a resource is protected behind an access gateway, when a request comes for this protected resource, the gateway forwards it to identity store for verifying the user, at this time a 302 is returned, once verified, request is sent back to access gateway from where user is able to access websocket resource.

How to process incoming sms using Twilio

I am using Twilio for sending SMS from my Java Web Application. I have a Twilio number purchased under my account. Now I am trying to process the incoming SMS to my Twilio number. All I am trying to do is to pass the message data and the sender of the message as an HTTP GET method to my application. I have found the following under my account settings:
In my application, I can add a REST service that can accept these details and save the required details to my database. But I am unable to find any example related to this. Is there any way to get the message details whenever a message is received.
Twilio makes HTTP requests to your application just like a regular web
browser. By including parameters and values in its requests, Twilio
sends data to your application that you can act upon before
responding.
https://www.twilio.com/docs/api/twiml/sms/twilio_request#twilio-data-passing
When Twilio receives a message for one of your Twilio numbers it makes a synchronous HTTP request to the message URL configured for that number, and expects to receive TwiML in response.
Twilio sends parameters with its request as POST parameters or URL query parameters, depending on which HTTP method you've configured. https://www.twilio.com/docs/api/twiml/sms/twilio_request#request-parameters
If you are using Spring MVC annotations, you can add an annotated parameter to your method's parameters:
#RequestMapping(
value = "/someEndPoint",
method = RequestMethod.POST,
consumes = "text/plain"
)
public String someMethod(#RequestParam("param1") String paramOne) {
//use paramOne variable here
}

Rest error codes/ success code

I am working on REST project using jersey. On success I am returning 200 code along with the json response for particular request. I know there are may different classifications of error codes, like server error which start with 500, client error which start with 400 etc. My question is suppose we are subtracting some value in database for example count, for example count in database is 5 and request comes to subtract 3, it is valid and i will send request but my business rule states that count cannot be less than zero, so if request comes 6, i cannot subtract that , so in that case should i actually send status code as 200 and send error information is json respose {"errorCode" : "1","errorMessage":""} so i should send different HTTP status code like 5## that there is server problem or 4## saying bad request.
Can anyone please suggest me good (in the sense which is restful and follow all standars) REST project on github which I can refer.
If any error occurs during request processing you should never send a 2XX status code. Why? Because 2XX indicates successful processing which in this particular situation did not happen.
When you send a value to be subtracted from another value in DB and the assumption is that the result can't be lower than 0 you should reply with 409 Conflict HTTP status code and clarification in a response body stating e.g.:
The request can't be completed since the result value will be lower than 0.
It would be 400 Bad Request if null e.g. is sent instead of a number.
In the particular use case, you mentioned, you should return 400 as status code (bad request). errorCode in the json is your business domain, so you can use what you want ( Also, take a look at JSend standard for sending the http "error status" in the response https://labs.omniti.com/labs/jsend )
You're exactly right: you should send an HTTP "400" for a client error, a "500" for a server error, etc; along with a specific error message.
You may or may not want more granular HTTP status codes (for example, "403" for client authentication failed, otherwise "400" for other client-related errors).
Are are two good lists you can use for guidance:
Common MS-Azure REST Error Codes
HTTP Status Codes
NOTE:
There is no "standard" per se. The two links I gave above are useful "examples". The "official" IETF RFC for HTTP 1.1 Error codes is RFC 2616:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Categories