MyJavaCode.com

Tutorial and How to Guide on Java Programming. Topics covered include Java Programming Language - Core Java, Spring, Webservices, REST, Hibernate, Maven and Microservices.

  • Core Java
  • REST API’s
  • Spring boot
  • Hibernate
  • Interview Questions
  • Contact Us
  • Projects
  • Offerings
Java API to get Domain Authority and other Moz URL Metrics

Java API to get Domain Authority and other Moz URL Metrics

May 2, 2025 By Prasanna Manjunatha

Moz is one of the popular platform offering various tools and services for Search Engine Optimization. Keyword Research, Link Building, SEO Audit and Rank Tracking are some of the key services offered by Moz.

Services provided by Moz are extensively used by freelancers and Digital marketing companies to analyze and track the performance of websites in Seach Engines. For each of the sites, Moz provides analytical and ranking data. Mozrank and Domain authority are two of the key Moz metrics used by Digital marketers to derive the value and ranking potential of a given a website.

  • How to iterate Java HashMap
  • JaCoCo Code Coverage in Springboot Applications : A Comprehensive Guide
  • How to Password Protect a PDF File using Java : A Step-by-Step Guide

To enable Digital Marketers to build SEO solutions, Moz provides API’s (Mozscape API) which can be used to get link and rank metrics for any given website. In this article, we will go through the steps required to call one such API, the URL metrics API. By using this API, we can get metrics like Domain Authority, Page Authority, Moz Rank, Number of external links and many other metrics for a given website. The REST endpoint for the URL Metric API along with the values for the parameters would be in the below format,

https://lsapi.seomoz.com/linkscape/url-metrics/moz.com?Cols=4&Limit=10&AccessID=mozscape-ac52dbcf56&Expires=1545264000&Signature=bc0cc0d590fce266ba8f9fc26b996439

Now we will go through the steps (along wit Java code snippets) that we need to follow to invoke this API to get the desired Domain metric.

1. Get API Credentials

An AccessID and API key is a prerequisite for using any of the Mozscape API. AccessId is more like an username and it uniquely identifies your API account. API key would be your secret password linked to the AccessId. You can change the API key as and when you need.

To get the AccessId and API Key, first you need to signup for Mozscape account (either community account or pro). Once you log in, you can click on ‘Manage Mozscape API Key’ to generate the AccessID and the secret key.

Also Read: How to Generate MD5 Hash in Java

The AccessID we get from this step will be used as the value for AccessID field in the above GET API. The secret key will be used for generating the signature.

2. Prepare Signature

One of the parameters in the URL is the signature. The signature can be obtained by using the HMAC-SHA1 hash of AccessID, Expires (timestamp in seconds to indicate validity of the request) timestamp and secret key. The combination of AccessID and Expires parameter acts as the data and API key acts as a secret key. The generated secure hash should be base 64 encoded and then URL encoded before using as a value for the signature parameter in the request.

public String getHMACSHA1Hash(long timeStamp, String key)
            throws SignatureException, NoSuchAlgorithmException, InvalidKeyException
    {
        String data = AccessID + timeStamp;
        SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
        Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
        mac.init(signingKey);
        
        return new String(Base64.getEncoder().encode(mac.doFinal(data.getBytes())));
    } 
    return new String(Base64.getEncoder().encode(mac.doFinal(data.getBytes())));
}

3. HTTP call with basic authentication

Two other parameters that we have to pass in the request are the ‘Cols’ and ‘Limit’. The value for ‘Cols’ indicate the Moz metric that we want to fetch. The complete list of Cols values along with its description is available in the Moz API document. The ‘Limit’ parameter is used for limiting the number of results in the response.

Also Read: What Are REST APIs? A Beginner’s Guide for Java Developers

The Moz API makes use of Basic authentication for security. As you can see in the below code snippet, I am making use of AccessID and SecretKey for authenticating the request.

parameters.put("Cols", MozUtils.DomainAuthority_Cols);
parameters.put("Limit", "10");
parameters.put("AccessID", AccessID);
parameters.put("Expires", String.valueOf(timeStamp));
parameters.put("Signature", signature);


String urlParams = MozUtils.getParams(parameters);
finalURL = finalURL + "?" + urlParams;
UriComponents uri = UriComponentsBuilder.fromUri(new URI(finalURL)).build();

restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(AccessID, SecretKey));  
ResponseEntity<URLResult> response = restTemplate.getForEntity(uri.toUriString(), URLResult.class);

Here I am using Spring Rest Template for making the above HTTP API call.

4. Parse the output and get the Metric

The fields in the response depends on the values you have passed for the ‘Cols’ parameter in the request. You can get the complete list of response fields along with the description from the Moz API document.

URLResult urlResult = response.getBody();
        
URLMetric urlMetric = new URLMetric();
        
urlMetric.setDomainAuthority(urlResult.getPda());

By making use of the above steps, I have a developed a wrapper REST API which returns a particular Moz metric given the domain name. If you want a different Moz metric, you just need to change the value against ‘Cols’ parameter in the source code before making the request. You can find the complete source code for this project in GitHub.

 

Also Read: JaCoCo Code Coverage in Springboot Applications : A Comprehensive Guide

email
print

About Prasanna Manjunatha

Prasanna is a Toronto based Java Consultant with more than 15 years of Software Development experience. His areas of expertise include Core Java, Spring boot, REST, Microservices, Hibernate, NoSQL, Docker, Kubernetes and AWS.

Currently Trending

  • Five minutes guide for creating SOAP web service in Java using Axis2
  • How to Extract Private Key from Java Keystore (.JKS) or .P12 File
  • HTTP Redirection Configuration in JBoss
  • How to Generate MD5 Hash in Java
  • How to Update MySQL Collation for all tables in the schema
  • MySQL Scheduler Overview with Examples
  • Java Null Check Using Optional: Enhancing Code Reliability and Readability
  • How to Solve Maven invalid CEN header error
  • How to Check Free Disk Space in Java
  • How to Password Protect a PDF File using Java

Connect with us

  • Facebook
  • GitHub
  • LinkedIn
  • Twitter

TAG CLOUD

Axis2 Code Coverage CodeCoverage cron expression Data Structure Frameworks Hashing HashMap Hibernate IntelliJ java Java Mail jboss jpa 2.1 Maven MyBatis MySQL PDF Quartz REST REST API SOAP Springboot Spring boot SQL Tools Tutorial web service

All time Popular Posts

  • How to Extract Private Key from Java Keystore (.JKS) or .P12 File
  • How to check whether a Collection is Null or Empty in Java
  • How to Solve Maven invalid CEN header error
  • How to configure JaCoCo for Code Coverage in Spring boot Applications
  • How to Send Email In Java
  • How to Create Cron Expression for Quartz Scheduler
  • Getting Started with Spring Boot: A Spring Boot Setup Tutorial
  • How to Password Protect a PDF File using Java
  • How to Generate MD5 Hash in Java
  • How to Deploy Exploded WAR file in JBoss EAP Server

Copyright © 2026 MyJavaCode.com