The Moz Api V2 PHP Library – Documentation

The Moz API V2 PHP Library is an open source PHP wrapper to get query data out of Moz’s API v2. It is used to retrieve information out of Moz’s API such as Anchor Text Metrics, Final Redirect, Global Top Pages, Global Top Root Domains, Index Meta Data, Link Intersects, Link Status, Linking Root Domains, Link Metrics, Top Pages Metrics, URL Metrics and Usage Data from over 36.5 Trillion different links.

This library is for anyone that is looking to build an SEO tool utilizing the PHP Programming Language.

Moz API V2 PHP Library – Dependencies

This library was written on PHP 7.2 and was written using file_get_contents so as not to incur the requirement of PHP-CURL on various hosting platforms. It does require PHP-JSON however.

Installation

Download the zip file from our github repository and add Moz.php to your php applications path. Our github repository can be found here:

Moz API V2 PHP Library on Githubhttps://github.com/media-giant-design/mozapiv2

Retrieve an access_id and secret from Moz.com. If you dont’ have one you can signup for a free account here: https://moz.com/products/api

Usage

Table of Contents


Brief Example of Use

<?php
// This require_once will vary depending on your php applications specific directory structure
require_once __DIR__ . DIRECTORY_SEPARATOR . 'Moz' . DIRECTORY_SEPARATOR . 'Moz.php';

//initialize the library
$moz = new Moz(your_access_id,your_secret);

//query some data
$result = $moz->urlMetrics("https://www.mediagiantdesign.com/");

//dump the result 
var_dump($result);

Usage Examples of Moz API V2 PHP Library

anchorText
Get metrics about anchor text used by followed external links to a target. Results are ordered by ‘external_root_domains’ descending.

@param $target string

@param $scope string

@param $limit int

@param $next_token string

@return object

$data = $moz->anchorText("mediagiantdesign.com");

var_dump($data);

finalRedirect
Returns the final redirect target of a page after following known redirects in the index. If no redirects are known, returns an empty response.

@param $page string

@return object

$data = $moz->finalredirect("mediagiantdesign.com");

var_dump($data);

globalTopPages
Returns the final redirect target of a page after following known redirects in the index. If no redirects are known, returns an empty response.

@param $limit int

@param $nextToken string

@return object

$data = $moz->globaltoppages();

var_dump($data);

globalTopRootDomains
Returns the top 500 root domains in the entire index with the highest domain authority values, sorted by domain authority.

@param $limit int

@param $nextToken string

@return object

$data = $moz->globalTopRootDomains();

var_dump($data);

indexMetaData
Returns an id that changes when the data in the index changes.

@param $limit int

@param $nextToken string

@return object

$data = $moz->globalTopRootDomains();

var_dump($data);

linkIntersect

Get sources that link to at least one of a list of positive targets and don’t link to any of a list of negative targets.
* Please note: This is a weighted endpoint which means that data returned from this endpoint will count as more than 1 row consumed when data is requested. Please see here for more information on weighted endpoints.

@param $positiveTargets array

@param $negativeTargets array

@param $min_matching_targets number

@param $source_scope string

@param $sort string

@param $limit int

@param $next_token string

@return object

$target1 = new stdClass();
$target1->target = "latimes.com";
$target1->scope = "root_domain";

$target2 = new stdClass();
$target2->target = "blog.nytimes.com";
$target2->scope = "subdomain";

$negTarget = new stdClass();
$negTarget->target = "moz.com";
$negTarget->scope = "root_domain";

$negTarget2 = new stdClass();
$negTarget->target = "google.com";
$negTarget->scope = "root_domain";

$data = $moz->linkintersect([$target1,$target2],[$negTarget],null,"page","source_domain_authority",50);     

var_dump($data);

linkstatus

Get information about links from many sources to a single target
* Please note: This is a weighted endpoint which means that data returned from this endpoint will count as more than 1 row consumed when data is requested. Please see here for more information on weighted endpoints.

@param $sources array

@param $target string

@param $target_scope string

@param $source_scope string

@return object

$data = $moz->linkstatus(["https://www.mapquest.com/"],"https://www.mediagiantdesign.com/","root_domain","root_domain");

 var_dump($data);

linkingRootDomains

Get linking root domains to a target@param $target_scope string

@param $target string

@param $target_scope string

@param $sort string

@param $filter string

@param $begin_date string

@param $end_date string

@param $limit int

@param $next_token string

@return object

$data = $moz->linkingRootDomains("https://www.mediagiantdesign.com/");

var_dump($data);

linkMetrics

Get links to a target.

@param $target

@param $scope string

@param $sort string

@param $filter string

@param $source_root_domain string

@param $source_scope string

@param $subdomains_limited_to_one array

@param $limit int

@param $next_token string

@return object

$data = $moz->linkMetrics("https://www.mediagiantdesign.com/");
 
var_dump($data);

topPages

Returns top pages on a target domain.

@param $target

@param $scope string

@param $sort string

@param $filter string

@param $daily_history_deltas array

@param $daily_history_deltas array

@param $daily_history_values array

@param $monthly_history_deltas array

@param $monthly_history_values array

@param $limit int

@param $next_token string

@return object

$data = $moz->topPages("https://www.mediagiantdesign.com/");

 var_dump($data);

urlMetrics

Get metrics about one or more urls.
Please note: This is a weighted endpoint which means that data returned from this endpoint may count as more than 1 row consumed based on the data requested. Please see here for more information on weighted endpoints and multiplier logic specific to the URL Metrics endpoint.

@param $target

@param $daily_history_deltas array

@param $daily_history_deltas array

@param $daily_history_values array

@param $monthly_history_deltas array

@param $monthly_history_values array

@param $distributions int

@return object

$data = $moz->linkMetrics("https://www.mediagiantdesign.com/");
 
var_dump($data);

usageData

Returns the number of rows consumed so far in the current billing period.
The count returned might not reflect rows consumed in the last hour. The count returned reflects rows consumed by requests to both the v1 (Mozscape) and v2 Links APIs.

@param $target

@param $daily_history_deltas array

@param $daily_history_deltas array

@param $daily_history_values array

@param $monthly_history_deltas array

@param $monthly_history_values array

@param $distributions int

@return object

$data = $moz->usageData();
 
var_dump($data);

Additional Information about the Moz API V2 PHP Library

The Moz API V2 PHP Library was built as part of Media Giant Designs’ upcoming SEO All In One tool. The projects goal is to provide an easy to use, lay person application that will easily guide SMB’s to better search engine rankings without the need for technical or SEO knowledge. If you’re interested in Media Giant Designs SEO services please visit our Search Engine Optimization (SEO) page.

For additional information regarding the technical details of the Moz API V2 itself please visit the MOZ’s Link API Documentation. It can be found here: https://moz.com/help/links-api