Hey there, fellow developer! Ready to supercharge your SEO tools with some SEMrush magic? Let's dive into building a SEMrush API integration using JavaScript. We'll be using the nifty node-semrush
package to make our lives easier. Buckle up!
Before we jump in, make sure you've got:
Let's get this show on the road:
mkdir semrush-integration cd semrush-integration npm init -y npm install node-semrush
Easy peasy, right?
Now, let's set up our SEMrush client:
const SEMrush = require('node-semrush'); const client = new SEMrush('YOUR_API_KEY_HERE');
Replace 'YOUR_API_KEY_HERE'
with your actual API key, and you're good to go!
The node-semrush
package makes it super simple to fire off requests. Here's a quick example to get a domain overview report:
client.domainOverview('example.com') .then(data => console.log(data)) .catch(error => console.error(error));
Cool, huh? There are tons of other methods available, like keywordOverview
, backlinks
, and more. Check out the package docs for the full list.
The responses come back as JSON, so they're easy to work with. Here's how you might handle that domain overview data:
client.domainOverview('example.com') .then(data => { const { organic_keywords, organic_traffic } = data; console.log(`Keywords: ${organic_keywords}, Traffic: ${organic_traffic}`); }) .catch(error => { console.error('Oops! Something went wrong:', error.message); });
SEMrush has rate limits, so be nice! The package handles this for you, but you might want to add some delays between requests if you're doing a lot of them.
Need to make multiple requests? Try something like this:
const domains = ['example1.com', 'example2.com', 'example3.com']; Promise.all(domains.map(domain => client.domainOverview(domain))) .then(results => console.log(results)) .catch(error => console.error(error));
And there you have it! You're now armed and dangerous with SEMrush API integration skills. Remember, with great power comes great responsibility (and potentially a hefty API bill if you're not careful).
Want to dive deeper? Check out the SEMrush API documentation and the node-semrush package for more info.
Now go forth and conquer the SEO world! 🚀