Parsing XML returned by SendNotification in exchangelib - exchangelib

I'm working on a python project to process emails as they arrive in a Microsoft inbox. Specifically, I want to set up a push subscription, receive notifications when a new email hits the inbox, and then construct and send another email based on the body of the one just received.
I'm at a loss to understand where "response.data" comes from since I can't find a reference to it anywhere in the documentation. The comment says:
When the server sends a push notification, the POST data contains a 'SendNotification' XML document. You can use exchangelib in the callback URL implementation to parse this data:
And the code in the example is:
ws = SendNotification(protocol=a.protocol)
for notification in ws.parse(response.data):
# ws.parse() returns Notification objects
pass
Where might I find a reference to this response.data?
Thanks in advance.

response.data is just a placeholder for whatever your web server framework calls the request object. The above code snippet is meant to be used in the web server code that handles the push events that Exchange sends to the URL that you defined when you created the push notification.

Related

how to send "messagebody" directly in api call to SQS queue via url without using postman?

i have api gateway with 3 simple backends:
2 basic api routes (/plus and /minus) backed by lambda functions
1 direct sqs queue (/sqs_send)
It means i can send via api call directly to my sqs queue.
2 lambda backend functions take 2 params 'a,b' from api call and add,subtract and show output.
https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/minus?a=10&b=20 # prints -10 in browser
https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/plus?a=10&b=20 # prints 30 in browser
The 3rd function is tricky for me. Via postman i managed to send directly to sqs like this via put request. Notice how i have to select "body" "raw" then input message. I did check the sqs queue - the msg from postman is there.
My question - what to type into my api gateway endpoint to send msg directly to sqs? Without using postman?
https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/sqs_send?mesagebody # what to type after sqs_send?
This did not work - returns {"message":"Not Found"}
https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/sqs_send?
Action=SendMessage&
MessageBody=This+is+a+test+message
Is it possible, my sqs_send api route does not work with parameters, because it is designed to only work with "messagebody" as per my settings? "Message attributes" is empty?
If I understood correctly, you want to call your API gateway endpoints by directly entering the URL into your browser's address bar.
Short answer:
Unfortunately you can't do this with your 3rd endpoint /sqs_send, because it is a PUT endpoint which the browser cannot call directly through the address bar.
Details:
Browsers usually support only HTTP GET and POST methods directly, through form submissions (which in turn is an HTML limitation, where form submissions only support these two methods). In GET method, parameters are appended to the end of the URL in the pattern example.com/?name1=value1&name2=value2. In POST method, parameters are included in the body of the request, so they're not visible in the URL itself. This means that you can only call GET endpoints by directly typing into the address bar of your browser. Your /plus and /minus are likely GET endpoints. POST endpoints must be called via HTML form submissions to include your parameters.
For calling other methods like PUT and DELETE (in addition to GET and POST), you will have to use XMLHttpRequest or the Fetch API, or some frontend framework method built around them. As your Postman screenshot shows, your third endpoint /sqs_send is a PUT, so you can't call it directly by entering the URL into the browser's address bar. If you must call it this way, you will have to convert your endpoint to a GET so that you can send your parameters via URL parameters.

Receive Callback request inside Postman automated test

I am trying to write automated tests with Postman. I am new to postman automation world so sorry if the question will seem dumb.
In the api that I need to test when I send a request I immediately receive a response with a transactionID, no matter transaction succeeded or not. Along with my request I send a CallbackURL to the server where I expect the actual transaction result to be called back. The server will do a PUT request back to the CallbackURL that I have provided with the transactionID and the actual response or error.
So the question is, can I have such kind of scenarios in my postman tests?
I guess I should run a web server and expose an endpoint which will expect a PUT request and I should get the body of this PUT request in my tests to check it, and respond back to it with success.
In other words, within my script I need to perform the following actions:
Do a request to the server passing a callback URL
check the immediate response from the server and keep the returned transactionID
Have a webserver run with an endpoint that I passed as a callback URL
Expect a request to that endpoint with transactionID and actual response
Check that the response is what I actually expected
Respond to the request with success
I was thinking about Postman Mock server, but seems it is not designed for such usage.
I also think may be I can run some JS Webserver (may be nodeJS) inside the postman Sandbox...
Actually I am very new to postman testing and I am really confused about this kind of issue. Is it even possible to do this with postman or I need something else?
There are some features provided by POSTMAN which can help you to resolve your problem
When you do request to server passing callback URL it gives you transactionID in response. Save that transactionID in environment variable or global variable. Same you can do it for callbackURL.
Eg. pm.environment.set("transactionID", transactionID);
Then you can do the second request where you passed callback URL and transactionID which you have already.
In short in POSTMAN there are features like
Set global and environment variable which helps to pass some values fetched from response to another request.
call other request on success of first request
eg. postman.setnextRequest({{requestname}});
If you can mentioned your problem statement little bit in details it will be easy to answer in better way.
Hope This Will Help You

Can we call GET/POST ajax call from Pentaho data integration spoon

I am using Django, Neo4j, and pentaho. In Pentaho Data Integration, we can use the javascript for any transaction. My question is that can we call ajax from the PDI javasticpt to django server method. Actually i want to send success msg to server after the ETL process done by the PDI. Following is the javascript I am trying.
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "http://127.0.0.1/url_name/?parameter=value", false);
xhReq.send();
Don't re-invent the wheel my friend!, use the "REST Client" step as the last step of your flow, and use the parameters in the step to specify the GET Method and URL with GET parameters to send. After executing the "REST Client" you will get the expected response as you specified in the parameters (maybe a JSON if your server answers it).
You don't need to code with javascript (actually is possible with User Defined Java Class with coding, but it's a more complex process).

Collect POST data, process it and POST that data to an external URL

I'm trying to implement a data processing module.
The scenario is,
First a user will POST some data.
User POSTed data needs to be processed and some more info needs to be added here
This processed POST data should be sent to an external URL with out user intervention.
The external URL will accept only POST requests.
Please suggest me a way to send this POST data to external URL.
Update
As suggested, I started using requests.
In the view that i collected the initial POST data, I'm compiling another data object with the user posted data (after processing) and adding some more data to the object and doing the post request as bellow
req = requests.post(post_url, data=post_obj)
the status_code returned is 200
But the data(post_obj) doesn't seem to be sent to the post_url. The post_url is prompting that it did not receive the POST data.
when I checked the req object,
req.request.data seems to have the post_obj information and req.request.url has the post_url
req.url has the redirect_url which is prompting that the post_url didn't receive any data.
My question is,
How to actually POST the data?
what is the object that needs to be returned in the view?
If the way I'm POSTing the data (requests.post method) is wrong. Please suggest me the appropriate way.
Note: After POSTing the data to the post_url, it will be redirected to a different page.
Use Urllib2, mechanise or requests (who all use pythons built in urllib2 and httplib) or pycurl (which uses libcurl) to do the posts to the external resource.
Requests is the easiest to work with, mechanize is great for filling out forms and programming like a browser, urllib2 is the underlying library so it's also important to know and pycurl is (imo) a last resort due to not being particularly maintained
You should consider using a queue to handle the server->third party step and then asynchronously report to the user that the task has completed, otherwise you face potentially timing your connections out if your 3rd party app takes to long to respond.
You can use the standard library urllib2 to do the 2nd POST.
I've also heard good things about the requests library, which should be easier to use than urllib2.

Connecting a desktop application with a website

I made an application using Qt/C++ that reads some values every 5-7 seconds and sends them to a website.
My approach is very simple. I am just reading the values i want to send and then i make an HTTP POST to the website. I also send the username and password to the website.
The problem is that i cannot find out if the request is successful. I mean that if i send the request and server gets it, i will get an HTTP:200 always. For example if the password is not correct, there is no way to know it. It is the way HTTP works.
Now i think i will need some kind of a protocol to take care the communication between the application and the website.
The question is what protocol to use?
If the action performed completes before the response header is sent you have the option of adding a custom status to it. If your website is built on PHP you can call header() to add the custom status of the operation.
header('XAppRequest-Status: complete');
if you can modify the server side script you could do the following
on one end :
You can make the HTTP post request via ajax
and evaluate the result of the ajax request.
On the serve side
On the HTTP request you do your process and if everything goes accordingly you can send data back to the ajax script that called it.
solves your problem .. ?