question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

complete API failure.

See original GitHub issue

The docs here state to use the ‘url’ if in the EU (why? why can’t this be handled on their end, or in the library?), but the url doesn’t match the one I’m given on the mailgun site.

Do I use https://api.eu.mailgun.net, per the docs here? Doesn’t seem to work, get a 401. Or https://api.eu.mailgun.net/v3, per the docs on the mailgun area in a few places? Get a JSON parsing error from inside the minified library. Or https://api.eu.mailgun.net/v3/<my-site,-yes-actually-my-real-site>.com, an attempt to extract the pattern from a curl example for the sandbox URL? Nope, JSON error. without v3? Still a JSON error.

What even is this guessing game? Some people are going back and giving up and just using the old deprecated library from 2018?? I wish I could–I tried, on accident, since the website’s docs erroneously point to the wrong lib (as pointed out in the issues here repeatedly–how is that not fixed yet?)

I don’t know if the old non-official one is able to work with EU, and I’m guessing not–just fails without a descriptive error for me.

On the other hand, I can’t get this one to work either.

On the other hand, I can’t even get a curl example to work with the eu endpoints. I finally finangled enough with a curl request to get it to not throw an error, but I just get stdout that says ‘Mailgun Magnificent API’… huh? No email received, and no email recorded as sent in the dashboard?

wtf?

Really feeling let down, I’ve never had such a bad API experience, honestly. It’s kind of shocking, for a company that purported to do one simple thing well for developers, for one of the single biggest web technologies out there.

Now the question is, is it possible for me to authenticate on the old API and I’m just doing something wrong, or is there really just no API option?

What a disappointment. 😕

I’ve got an extremely tight deadline, and this was the last stage. I really expected this to go more smoothly.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
kylebakeriocommented, Apr 12, 2021

For the next poor soul, this works locally as well as from heroku (including having actually received the email to my inbox, from the custom domain, from an eu domain).

Don’t do this at home, unless you’re up at 6am having pulled an all nighter to get a feature out the door, etc., etc.:

const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function mailgunWithCurl(to, subject, body) {
        const myDomain = 'mysite.com'
        const mailgunAPI = 'somlongalpha-numeric-codfewith-dashes123123'
        const mailgunURL = 'https://api.eu.mailgun.net/v3/yourwebsite.com/messages'
        
        // get this from your profile, and this is really important for eu domains; it'll include 'api' 
        // 'mailgun.net', may have a '/v3' or other number, and will then have your custom domain,
        // and then finally end with '/messages'. This one is mine, with the domain changed.
        
	let emailResult, emailError;
	
	async function hackedCurl() {
	  try {
	      const { stdout, stderr } = await exec(
	      	`curl -s --user 'api:${mailgunAPI}' ` +
	      	`${mailgunURL} ` +
	      	`-F from='Any Name <mailgun@${myDomain}>' ` +
	      	`-F to=${to}` +
	      	`-F subject='${subject}' -F text='${body}'`);

	      emailResult = stdout
	      emailError = stderr
	      console.log('stdout:', stdout);
	      console.log('stderr:', stderr);
	      return {
	      	result: emailResult,
	      	err: emailError
	      }
	  } catch (err) {
	      console.error(err);
		  emailError = stderr
	  	  return {
	      	result: emailResult,
	      	err: emailError
	      }
	  };
	};
	return hackedCurl();
}

This is completely self contained, don’t even need to npm install anything. Just add the vars, and copy paste.

Would love to see a better solution, but that’ll get me through for now. I’m feeling like there was an upgrade to the v3 api in the last 48 hours and I just happen to arrive on the scene at the wrong time or something.

1reaction
kstoltecommented, May 25, 2021

@kylebakerio I ended up needing to do the same thing. but for a non eu domain. took a different route though. https://github.com/mailgun/mailgun-js/issues/118#issuecomment-847792631. It stays out of the exec call and does it through node-fetch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web API Error Handling: How To Make Debugging Easier
Whether you're the consumer or producer of an API, you've no doubt seen that good error handling can make debugging easier.
Read more >
6 Frequently Occurring API Errors And How to Prevent Them
2. Unhelpful API Error Messages · 200 OK · 400 Bad Request · 401 Unauthorized · 403 Forbidden · 404 Not Found ·...
Read more >
Top 3 Reasons for API Failures | Blazemeter by Perforce
In this article, we'll look at three common reasons why API failures might happen, and how DevOps engineers can address them.
Read more >
Best practices for API error handling and troubleshooting
Best practices for Orange API error handling and troubleshooting.
Read more >
Three ways that APIs can fail | Computer Weekly
APIs permit external and internal applications and services to communicate with each other to perform or complete tasks and requests, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found