+0 votes
ago in Webmasters by (1.5m points)

How to use Mozscape API of MOZ with C #

1 Answer

+1 votes
ago by (673k points)
 
Best answer

In this article we are going to talk about how to use the MOZ API known as the Mozscape API using code in C # . To use Mozscape API of MOZ as always we will need some basic knowledge of the HTTP protocol if we want to understand the code in CSharp (C #).

The purpose of this code example in C # is to obtain the parameters DA (Domain Athority) and PA (Page Authority) . If you don't know what these two terms mean, you can read the following article where I describe what is Domain Authority and Page Authority .

The first thing we will need is to register for free on the MOZ website and get the API data "Access ID" and "Secret Key" . The "Secret Key" must be generated and takes a few minutes to be valid, so we will have to wait a while before using it.

image

With these two values "‹"‹we get access to the MOZ API (Mozscape) for free, but the functionality is reduced to obtaining a few parameters, but it is enough to get the DA and PA values. We can see a complete list of what values "‹"‹we can obtain with the free API and which with the payment API in the link http://apiwiki.moz.com/url-metrics#cols

The previous link will also help us to obtain the "Bit flags" which is nothing more than a number with which a metric is identified, for example the flag bit of the DA metric is 68719476736 and the flag bit of the PA metric is 34359738368 .

Use MOZscape API of MOZ with C #

Once we have all the necessary data we have talked about before we move on to the programming section in C #. The HTTP protocol with the GET method is used to make the request to the Mozscape API .

An example of the request URL would be:

http://lsapi.seomoz.com/linkscape/url-metrics/www.vozidea.com?Cols=68719476736&AccessID=member-ace8g6ka76&Expires=1389795965&Signature=AJzro%2YUw%2Fc6J8xOP35cVRmJVxMc%3D

We will analyze all the elements of the URL one by one and then we will talk one by one about those who need some kind of explanation:

  • Host name and resource : http://lsapi.seomoz.com/linkscape /
  • Metric set definition : url-metrics
  • URL under study : www.vozidea.com
  • Metric / s we want to obtain : Cols= 68719476736
  • Time and exact date at which our API request expires : Expires=1389795965
  • Authentication signature : Signature=AJzro%2YUw%2Fc6J8xOP35cVRmJVxMc%3D

Host Name and Resource

As for the host name, only to say that we can use both the HTTP version and the HTTPS version, I will use the HTTP version in the code.

Metric set definition

As for the set of metrics we will use "url-metrics" , but there is more and you can find them in the following link: http://apiwiki.moz.com/categories/api-reference

URL under study

It is the URL we want to analyze, in the example it is the domain www.vozidea.com .

Metric / s we want to get

In this parameter we are going to stop a little more since it is important. This is the Cols parameter in the example and whose value is a number, which consists of a flag bit (in this case it is the flag bit of the DA).

The point is that I also want to obtain the PA so that the API returns the DA and the PA I have to give the parameter Cols the value of the sum of the bit flags of DA (whose flag bit is 68719476736) and PA (whose bit flag is 34359738368) which would be: Cols=103079215104

If I needed to obtain more metrics I would add their flag bit values and give the value of the sum to the Cols parameter.

Time and exact date at which our API request expires

This is the Expires parameter, whose value is: total seconds elapsed from the UNIX origin date (January 1, 1970) to the present time + 300 seconds.

This value indicates a future date and time, specifically 300 seconds (5 minutes) from the future. In other words, every request we make to the API will expire after 5 minutes .

I have set the value of 5 minutes because I recommended it in the API documentation but if you need a higher value you can modify it in the code. To create the Expires parameter in the code in C #, the CreateExpiryTimestamp() function is CreateExpiryTimestamp() .

Authentication signature

It is the most complex parameter to obtain and consists of a signature of authenticity. This confirms to the Mozscape API that we are authorized to use the API .

To sign the request we use the Signature parameter that consists of encoding a message with the HMAC-SHA1 algorithm. This message consists of the Access ID , line break (represented by the \n character pair) and the Expires parameter. We encode this message with the HMAC-SHA1 algorithm and use the Secret Key as the coding Secret Key .

Make the HTTP request to the Mozscape API

Recall that all the data that are part of the URL of the request if there are special characters in the value of any parameter must be encoded with URLEncode , so the Uri.EscapeDataString() function is Uri.EscapeDataString() in the code in C #.

Finally we make the HTTP request to the URL that we have formed with the previous parameters and the API will return a response in JSON format that can be for example:
{"pda":14.931787896224872,"upa":25.93463975359981}

In this answer "pda" and "upa" are the values "‹"‹of the DA and PA of www.vozidea.com.

And we have everything ready to download the project in C # and start experimenting.

image

If you liked the article on how to use Mozscape API of MOZ with C # or if you have doubts do not hesitate to comment.


...