Mandrill API error for send request - jersey

I have a problem while sending a message via Jersey client on Mandrill API. I use Jersey client as follows:
ClientBuilder.newClient()
.register(JacksonJsonProvider.class)
.target(“https://mandrillapp.com/api/1.0/messages/send.json”)
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.json(methodEntity));
Below you can see logged headers, method and content of the API request.
POST https://mandrillapp.com/api/1.0/messages/send.json
Accept: application/json
Content-Type: application/json
{"message":{"subject":"Hello World!","text":"Really, Im just saying hi from Mandrill!","to":[{"email":"marcel#xxxx.com","name":"Marcel cccc","type":"to"}],"headers":{},"tags":["test"],"from_email":"info#xxxxx.com","auto_text":true,"preserve_recipients":false},"async":false,"key":"EWIBVEIOVBVOIEBWIOVEB"}
In response to this request I keep receiving following message:
[{"email":"marcel#XXXX.com","status":"rejected","_id":"0ea5e40fc2f3413ba85b765acdc5f17a","reject_reason":"invalid-sender"}]
I do not know what the issue may be, from some posts I figured out I must use UTF-8 to encode my message and headers. But setting encoding to UTF-8 did not do much good. Otherwise the payload seems fine to me and moreover I found on forums that invalid sender can mean any other kind of issue (not just invalid sender which is sad).

I had exactly same problem with
"reject_reason":"invalid-sender"
You probably check already similar question Mandrill “reject_reason”: “invalid-sender”
Try it if it helps. I realize that you also missing header parameter in your request
e.g. User-Agent: Mandrill-myclient/1.0
Please try also add this parameter to your Jersey Client setup as following:
ClientBuilder.newClient()
.register(JacksonJsonProvider.class)
.target(“https://mandrillapp.com/api/1.0/messages/send.json”)
.request(MediaType.APPLICATION_JSON_TYPE)
.header("User-Agent", "Mandrill-myclient/1.0")
.post(Entity.json(methodEntity));
Does it help?

Related

Handling text/plain request in Laravel (sent via navigator.sendBeacon)

Problem:
I am trying to get the content / body from a text/plain POST request in a Controller in Laravel 8.
Nothing in the docs or numerous google searches worked.
I have tried:
$request->input();
$request->all();
$request->json();
json_encode($request);
All of these seem to show that the request is completely empty.
Context
This may not be relevant to the solution, but might help other's who are trying to google this problem: The request I am trying to handle with my controller is being sent by navigator.sendBeacon on the client side. The request body is actually stringified JSON, but sendBeacon does not allow you to send requests with content-type JSON. Devtools show the content-type header for this request as 'text/plain'.
My Answer:
Use $request->getContent() to get the content of a text/plain HTTP request.
And then, if you are in a situation like mine where the text is actually JSON, use json_decode($request->getContent(),true) to get a standard PHP array from the content which you can use in your Controller.
It turned out to be quite simple, but the information was not in the docs, or in any online searches so I thought it would be worthwhile to post to SO anyways...
You can send the data as JSON like this instead
data = new Blob([JSON.stringify(data)], {type : 'application/json'})
navigator.sendBeacon('/your/route/here', data)

Slack Bot OpenModal Error: missing_post_type

I newly started with Slack Bot programming and I got an issue.
I am using Zapier as a webhook, and I created a new message with a button.
Now I want to open a modal like documented here: https://api.slack.com/methods/dialog.open#arg_token
For that, I make a POST Request via Zapier Webhooks like this:
Instead of that the modal opens, I get a response with an error message "error
missing_post_type"
I hope some expert can help me with this issue.
Thank you for the support!
The solution can be found in the linked documentation.
The method was called via a POST request and included a data payload, but the request did not include a Content-Type header.
You only need to add the content-type header. Then the post request should work.
Content-Type: application/json

POST request with Content-Type application/x-www-form-urlencoded and

My requirement is very simple.
Call POST request with id and password.
Header has Content-Type = application/x-www-form-urlencoded
and data is also passed as urlencoded like below
Response is coming in xml format.
I tried a lot of examples from everywhere but nothing seems to be working. It gives me back 401 Unauthorized which is an error that target API throws if request is not in proper format.
http://zetcode.com/java/getpostrequest/
Exactly what I needed.
Java HTTP POST request with HttpURLConnection section on the page did the work.

Is it IMPOSSIBLE to POST JSON with XDomainRequest?

As I am not able to find a way to set the content-type to JSON for the data I sent via XDomainRequest,
I naturally ask:
Is it IMPOSSIBLE to POST JSON with XDomainRequest?
"Only text/plain is supported for the request's Content-Type header"
Looking at some other questions, I'd say this is possible.
For example: How to send JSON data in XDR using the POST method
You can still POST the JSON as plain text and have the server side read the POST body directly and handle it, even Content-Type is missing for the sick of IE.
According to http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
You cannot send content-type : application/json in xdr. You can not even send any other custom header.
xdr is only limited to text/plain
The best you can do is use JSON.stringify() and parse it on server side.
xhr.send(JSON.stringify(jsonObject))

How can I get response header via cross-domain ajax?

I'm trying to read documentation and I must confess it is not an easy reading. I have no problem (after adding Access-Control-Allow-Origin header) to read responseText, but fail to get response header anywhere except Firefox.
So, my question is what is the right way to get response header, using cross-domain ajax?
I've tried to use (Access-Control-Expose-Headers), but, again, failed to read header.
So the way it should work is that you specify the headers you want the client to have access to in the Access-Control-Expose-Headers header. For example, if your server sets a Foo response header, and you want the client to be able to read it, your server should also send the following header:
Access-Control-Expose-Headers: Foo
On the client side, you can read all the response headers by calling xhr.getAllResponseHeaders(). This returns the response headers as a string, which you can then parse into an object using the following code: https://gist.github.com/706839
That is an explanation of how things should work. However, note that there is a bug in older browsers where the response headers can't be read on the client. See here for more details: CORS xmlhttprequest HEAD method
I had same problem, and found answer on Chromium mailing list that this is fixed in webkit, and it will be implemented in crhomium ~19.
I will try to find topic and update my answer.

Resources