Mailgun send via HTTP API doesn't seem to send - mailgun

I am trying to use Mailgun to send via the HTTP API as follows:
Python:
def send_simple_message(string):
return requests.post(
"https://api.mailgun.net/v2/samples.mailgun.org/messages",
auth=("api", "my-key"),
data={"from": "<me#mydomain.com",
"to": ["to#recipient.com"],
"subject": "",
"text": string})
My domain is verified using the CNAME records supplied, and I tried sending a couple of test strings.
Nothing visible happened, at all, from my Python script - didn't appear in sent items (gmail). So I tried manually via Terminal, and got the response: <Response [404]>.
Updating the address to mydomain.com (thanks #kwatford) I get <Response [200]> (success).
However, this was a test email I sent to myself (on a different address). I have not received the message, and it is not in the sent box of me#mydomain.com either. What have I done wrong?

Thanks to #kwatford for identifying the issue, exact solution as follows for anyone else confused by the example:
https://api.mailgun.net/v2/samples.mailgun.org/messages should be replaced by:
https://api.mailgun.net/v2/yourdomain.com/messages.
What I initially tried for a [200] response was simply http://mydomain.com which is incorrect.
Further, I was wrong to expect it to appear in sent items, though it does appear (now that I have the correct POST address!) in cp > logs on mailgun.com

Related

Getting "invalid_payload" and 400 response when trying to send data to a slack channel through Postman

I'm using postman to trigger a message using the slack channel's incoming webhook url. I tried the following curl and it works:
curl --location --request POST 'https://hooks.slack.com/services/T026NT2D4/B02UM3G1D35' \
--header 'Content-type: application/json' \
--data-raw '{"text":"Hello world"}'
I need to send aws S3's presigned URL to this channel but no matter how I try sending the data, I always get invalid_payload as the response. I tried sending it as Json message, Raw text and even tried x-www-form-urlencoded. Nothing seems to work.
I need some implementation example for this. Also, I'll be using spring boot to generate and send the message, so any resources on beautifying the message would be really helpful.
I've seen examples where the slack channel has some text and "more" option, which, upon clicking downloads a file(I'm assuming this "more" is a hyperlink of the presigned URL)
EDIT:
I was trying out a few more stuff. When I send the Json with only one field and specifically naming that filed "text", I'm able to send the message.
So my payload looked liked this:
{
"text": "*Presigned URL*"
}
The headers had Content-type as application/json.
Even if I changed "text" to "Message" I'm getting a 400 response. Is that what no_text means? that there is no "text" field in the payload
Just putting it here in case someone needs this.
That is the case, a "text" field should be there in the json message.
Link to slack guide
Found this implementation in case anyone wants to use slack SDK in spring boot : Implementation Link

WhatsApp Business API not sending /message endpoint or test messages to phone

I've setup a WhatsApp Business to test their new WhatsApp API for sending messages. I've followed the getting started guide, but I'm running into an issue when trying to send a test message to my phone.
I tested sending messages using the test message call in the business settings as shown in the guide and I've created my own /messages call in Postman using a permanent token. Both calls return a 200 status, but neither of them actually sends a message to my phone.
To double check my setup, I added a colleagues phone to the setup and he receives the messages and can interact with my webhook via WhatsApp just fine.
Some posts on Stackoverflow mention having to send a message to the test number first, but I was unable to get this to work and my colleague didn't have to do this.
Is there some kind of setting or issue that could explain why I'm not receiving the messages? I've even tried re-installing WhatsApp and setting up my phonenumber again, but that didn't change anything either.
Updates:
I tried validating my phonenumber via the /contacts endpoint, but it keeps returning an auth error. Updating my token to include all Whatsapp permissions did not change this, whatsapp_business_api_data isn't an option to include.
{
"error": {
"message": "(#100) The parameter whatsapp_business_api_data is required.",
"type": "OAuthException",
"code": 100,
"fbtrace_id": ""
}
}
I noticed that my webhook included a status object in change.value.statuses.[0] this mentioned the following:
{ status: 'failed', errors: [{ code: 131000, title: 'Failure due to an internal error. Please retry.' }]}
Next I created a new app and added the Whatsapp integration, I added and validated my phonenumber via a text and tried to send a test messsage. This also doesn't start a conversation nor does it give me any feedback. If I try to add my phonenumber again, by adding it as another number, I cant and get the error Reason: VERIFIED
So it's not the best answer to the issue, but I got a new phonenumber to test this out on. I added it to my test numbers, validated the number, sent a test message to the new number and received it just fine.
I'm not sure if the issue was caused by a privacy setting or an issue on Facebook side, but the old number still doesn't receive the messages.
You can only send a template type message as your first message to a user.
From the error message, it looks like you're hitting the Graph API version lower than v12.0. Try with V12.0 and higher.
Also, it will be helpful if you can paste the response you get from your API request and in your Webhook.
I had the same error code but with a different message:
I fixed it by deleting the whatsapp number here and adding it again.
Check the company code. It should be prefixed.
{ "messaging_product": "whatsapp", "to": "91xxxxxxxx", "type": "template", "template": { "name": "hello_world", "language": { "code": "en_US" } } }
Some colleagues weren't receiving any messages.
In my case, the problem was that they haven't accepted the WhatsApp's Terms and Condition.
To accept the terms, they had to start a new conversation with the business.
A popup appears to review and accept the terms.
Once accepted, they received the messages without problem.
PS: I'm in Spain, maybe it's a European Union thing...
I got the same issue, resolved it by sending the message multiple times through the api in watsapp setup, getting started page. Also accepted the number in personal watsapp by allowing it to continue.

How to use Mailgun sandbox?

I am currently testing Mailgun. Therefore, I don't want to add any payment information at the moment.
So, I'm working with the sandbox, and a verified address in the authorized recipients attached to the sandbox. So far, following the documentation, this limited setup is supposed to be working for testing purpose.
I use Postman to better identify how to work with the API, excluding any potential issues with coding.
Here is my Hello World config:
POST https://api:____my_API_Key___#api.mailgun.net/v3/sandboxXXXXX.mailgun.org/messages
The dashboard indicates that the sandbox is located in the US, so I don't use the european API.
Body:
from: postmaster#sandboxXXX.mailgun.org (also tried the verified email address, and postmaster <postmaster#sandbox...>)
to: bob#marley.com (the verified email address)
subject: test
text: Hello World!
I get a 400 error, Bad Request, and the documentation suggests to look for missing parameters.
The other posts I found so far did not help me to find the error spot either.
Also, Mailgun provides a Postman collection. But it did not help either.
Indeed, I dream of a detailed information of the API requirements, value formating... What are the required parameters if the error means I miss some?
Any idea of what I am missing?
Here is the solution.
I had to guess and analyze some examples from the provided Postman Collection to find out what the documentation is supposed to explain in the first place:
4 Required headers:
Authorization
Value : Basic XXXXX, where XXXXX is the Base 64 encoded version of api:___your_API_key___.
Content-Type
Value : multipart/form-data; boundary=XXX, where XXX is any short single string that will be used to identify a boundary within the sent content.
Content-Length
Value : XXX, where XXX is the size of the body request.
Host
Value : mydomain.com, your IP if sending from Postman...

parameter postman-token couldn't find in SoapUI request

I am getting familiar with both Postman and SoapUI. I already have a doubt. When I make a GET call with from the postman-echo service, I get slightly different responses shown to me in Postman and in SoapUI.
In particular, in Postman I get
"postman-token": "1ef2b330-3a46-4681-a304-d72f020cb194"
This field-value pair is not shown by SoapUI.
Can anyone explain me the apparent difference?
The parameter postman-token being added while you send a request from Postman. So, it's a custom parameter, you cannot expect it to be present with other tools.
If you check Postman doc of General settings They have explained what is that param is for:
This is primarily used to bypass a bug in Chrome. If an XmlHttpRequest
is pending and another request is sent with the same parameters then
Chrome returns the same response for both of them. Sending a random
token avoids this issue. This can also help you distinguish between
request on the server side.
You can disable it from Postman settings. Goto Settings > General > Send Postman Token header.

Unable to send mail via Mailgun over api or smtp

I have setup a new account and not verified my domain. I would like to test and confirm mail-send before proceeding with verification and adding payment information.
I have tried curl using the sandbox method and api key (including smtp). I have also tried to use my domain using the top account mail-address as recipient. But each time the send command (both curl and smtp) I get "Mailgun Magnificent API" response - but no mail is delivered. So far the Mailgun API does not look so Magnificent... I have gone through the documentation multiple times and cannot find what I might be doing wrong..
Any help is much appreciated.
Faced the same issue while sending emails via api by php curl. I solved it by changing API Base URL https://api.mailgun.net/v3/YOUR_DOMAIN_NAME to https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages.
It's because their api is not only for sending.
Hope this helps.
For anyone else trying to figure out what "Mailgun Magnificent API" means in a Mailgun HTTP 200-OK API response, it occurs when posting to https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/some/api/endpoint when /some/api/endpoint is not a valid Mailgun API endpoint.
If you are using a client library, there's probably a mistake in your Mailgun sender domain setting. Say you've verified the domain mg.example.com with Mailgun. Examples that can result in "Mailgun Magnificent API" (the exact setting name depends on the library):
MAILGUN_DOMAIN = mg.example.com # comment—this is a common mistake in dotenv files, which don't usually support inline comments; move the # comment to its own line
MAILGUN_DOMAIN = mg.example.com/mysite—get rid of the /mysite part
If you are posting directly to the Mailgun API (or developing a client library), there are some additional ways you might get "Mailgun Magnificent API":
Omitting the API endpoint: https://api.mailgun.net/v3/mg.example.com (as noted in another response)
Misspelling the endpoint: https://api.mailgun.net/v3/mg.example.com/massages (that should be messages with an e)
Including a # or ? after your domain: https://api.mailgun.net/v3/mg.example.com #/messages (see the note above about comments in config files)
Including an extra path after your domain: https://api.mailgun.net/v3/mg.example.com/route/to/my/app/messages
Note that you won't see "Mailgun Magnificent API" if YOUR_DOMAIN_NAME is not a valid sending domain you've registered with Mailgun. (In that case, Mailgun instead responds 404-Not Found).
The mailgun guide shows you to use https://api.mailgun.net/v3/YOUR_DOMAIN as YOUR_DOMAIN_NAME as in the snippet below and this was the problem.
If you're using mailgun-js, you simply need to have YOUR_DOMAIN as YOUR_DOMAIN_NAME.
No need for the https://api.mailgun.net/v3 part
const API_KEY = 'YOUR_API_KEY';
const DOMAIN = 'YOUR_DOMAIN_NAME';
const mailgun = require('mailgun-js')({apiKey: API_KEY, domain: DOMAIN});
const data = {
from: 'Excited User <me#samples.mailgun.org>',
to: 'foo#example.com, bar#example.com',
subject: 'Hello',
text: 'Testing some Mailgun awesomeness!'
};
mailgun.messages().send(data, (error, body) => {
console.log(body);
});
The problem for me was not including my domain name in the url and trying to type everything onto a single line. Strictly following their online example. Typing a backslash will bring your cursor to a new line.
$ curl -s --user 'api:key-xxx' \
https://api.mailgun.net/v3/your_domain/messages \
-F from='User <user#sample.mailgun.org>' \
-F to='xxx#gmail.com' \
-F subject='Hello' \
-F text='Testing some mailgun!'
Response
{
"id": "<xxx.x.xxx#your_domain>",
"message": "Queued. Thank you."
}
Including an slash "/" after messages url part at the end causes this failure too.
For example if you are using a library like Refit for c#, ensure your service interface be declared like this (see the Post attribute):
public interface IMailgunService
{
[Post("")]
Task<JsonDocument> SendEmailAsync([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> data);
}