Hey folks, I’m having a tough time switching from the old HTTP package to fetch in my Meteor app. I’ve been using HTTP to send emails via Mailgun for ages, but now that it’s deprecated, I’m trying to use fetch instead.
But it’s not working. I’m getting a 400 Bad Request error. The weird thing is, the old HTTP version still works fine with the same params. Any ideas what I’m doing wrong here? Do I need to format the data differently for fetch?
I encountered a similar challenge when migrating from HTTP to fetch in my Meteor app. One crucial aspect you might be overlooking is error handling. With fetch, you need to manually check the response status and parse the JSON.
Here’s a refined version of your code that addresses this:
This approach ensures you’re sending form-encoded data and properly handling responses. It’s been reliable in my projects, so give it a try and see if it resolves your issues.
hey there, i ran into this too. emma’s right about the form data, but i found another trick. try using the ‘node-fetch’ package instead of the built-in fetch. it handles things a bit differently and might solve ur problem without changing too much code. worth a shot!
I’ve recently tackled a similar migration in my Meteor project. The issue you’re facing likely stems from how fetch handles form data compared to HTTP. With Mailgun’s API, you need to send the data as form-encoded, not JSON.
This should resolve the 400 error. Remember to handle the response appropriately, as fetch doesn’t throw on HTTP error statuses like the old HTTP package did.