---
title: Code Examples
description: Code Examples
---

[Skip to content](https://support.above.com/-code-examples#main-content)

![above-logo-466-1](https://support.above.com/hs-fs/hubfs/above-logo-466-1.png?width=230&height=43&name=above-logo-466-1.png)

- [Buy Domains](https://www.above.com/marketplace/index.html)
- [Sell Domains](https://www.above.com/sell-my-domains.html)
- [Monetize](https://www.above.com/monetization.html)
- [Register](https://www.above.com/registrar/index.html)
- About
  
  Show submenu for About

    - [About Us](https://www.above.com/about.html)
    - [Above & Beyond Club](https://www.above.com/above-beyond-club.html)
    - [Brokerage](https://www.above.com/domain-brokerage.html)
    - [Contact Us](https://www.above.com/contact.html)
    - [Our Team](https://www.above.com/our-team.html)
- [Log In](https://www.above.com/login.html)

Open main navigation

Close main navigation

- [Buy Domains](https://www.above.com/marketplace/index.html)
- [Sell Domains](https://www.above.com/sell-my-domains.html)
- [Monetize](https://www.above.com/monetization.html)
- [Register](https://www.above.com/registrar/index.html)
- About
  
  Show submenu for About

    - [About Us](https://www.above.com/about.html)
    - [Above & Beyond Club](https://www.above.com/above-beyond-club.html)
    - [Brokerage](https://www.above.com/domain-brokerage.html)
    - [Contact Us](https://www.above.com/contact.html)
    - [Our Team](https://www.above.com/our-team.html)
- [Log In](https://www.above.com/login.html)

 How can we help you?

- There are no suggestions because the search field is empty.

1. [Above.com FAQ](https://support.above.com/?hsLang=en)
2. [Portfolio Manager Manual](https://support.above.com/portfolio-manager-manual?hsLang=en)
3. [Monetization API](https://support.above.com/portfolio-manager-manual?hsLang=en#monetization-api)

# Code Examples

#### **PHP Code Examples**

Here are some code examples for connecting to the Monetization API via PHP. Be sure to replace user and pass with your Monetization username and password, respectively.

Note: The below code examples have been tested in PHP 5 only. For compatibility with other PHP versions, some modifications may be required.

1. **Reportlist Function Example**This code example will retrieve a list of all generated reports and their statuses, using the API function reportlist.  
   **\<**?php
   
   **// define credentials$username** **=** **"user";$password** **=** **"pass";$api\_key** **=** **"key";// define settings$start** **=** **"0";** **// Report record to start from$number** **=** **"10";** **// How many report records to show## Get a list of previously generated reports, using API function reportlist#// create query URL, correctly URL encoded -- It is best to urlencode all values, just in case$query\_url** **=** **"https://www.above.com/api.php?username="** **.** **urlencode($username) .** **"&password="** **.** **urlencode($password) .**        **"&api\_key="** **.** **urlencode($key) .** **"&mode=reportlist&start="** **.** **urlencode($start) ."&num="** **.** **urlencode($number);// attempt connection and to put response into variable $res$res** **=** **file\_get\_contents($query\_url);// if connection was successfulif($res) {**   **// parse XML results**   **// put response in XML object $results**   **$results** **=** **simplexml\_load\_string($res);** **// you could also use a regex to get data, but this way is neater**   **// check for error**   **if($results-\>**error**) {**      **// if there was an error, get reason and display**      **$error\_attributes** **=** **$results-\>**error**-\>attributes();**      **// display error**      **echo** **"Error: "** **.** **$error\_attributes-\>**error**;**   **}** **elseif($results-\>**getName() == **"results") {** **// if there was NOT an error**      **// get list**      **foreach($results-\>result** **as** **$result){**        **// get attributes of each result**        **$result\_attributes** **=** **$result-\>attributes();**        **// print report details**        **echo** **"Report ID: "** **.** **$result\_attributes\['reportid'\]** **.** **", Generated: "** **.** **$result\_attributes\['generated'\]** **.**            **", Status: "** **.** **$result\_attributes\['status'\]** **.** **"\\n";**      **}**      **// end get list**   **}}** **else** **{** **// if there was a connection error**   **// print error**   **echo** **"Connection error!";}**?**\>**
2. **Fetch Function Example**This code example will retrieve a generated report, using the API function fetch.  
   **\<**?
   
   **// define credentials$username** **=** **"user";$password** **=** **"pass";$api\_key** **=** **"key";// define settings$reportid** **=** **"12345";** **// ID of the report to fetch$start** **=** **"0";** **// Report record to start from$number** **=** **"20";** **// How many report records to show## Get a list of previously generated reports, using API function reportlist#// create query URL, correctly URL encoded -- It is best to urlencode all values, just in case$query\_url** **=** **"https://www.above.com/api.php?username="** **.** **urlencode($username) .** **"&password="** **.** **urlencode($password) .**        **"&api\_key="** **.** **urlencode($key) .** **"&mode=fetch&reportid="** **.** **urlencode($reportid) .** **"&start="** **.** **urlencode($start) .**        **"&num="** **.** **urlencode($number);// attempt connection and to put response into variable $res$res** **=** **file\_get\_contents($query\_url);// if connection was successfulif($res) {**   **// parse XML results**   **// put response in XML object $results**   **$results** **=** **simplexml\_load\_string($res);** **// you could also use a regex to get data, but this way is neater**   **// check if any children exist for \<results\> -- which indicates report is not returned**   **if(** **count($results-\>**children()**)** != 0 **) {**     **// check for error**     **if($results-\>**error**) {**        **// if there was an error, get reason and display**        **$error\_attributes** **=** **$results-\>**error**-\>attributes();**        **// display error**        **echo** **"Error: "** **.** **$error\_attributes-\>**error**;**     **}** **elseif($results-\>**getName() == **"results") {** **// no error, but status returned**          **// get status of report**          **$status** **=** **$result-\>attributes();**          **if($status\['status'\]** == **"Generating") {**            **// show status**            **echo** **"Report is currently generating - try again in a few minutes.";**          **}** **else** **{**            **// unknown status**            **echo** **"Unknown Status: "** **.** **$status\['status'\];**          **}**     **}**   **}** **elseif(** **count($results-\>**children()**)** == 0 **) {** **// report is ready and has been returned      #      # What you do with the CSV output now is up to you!      # You could save it to a file or parse it and insert it into a database      #      # Remember: The first row is the heading - it does not contain values      #**      **echo** **"CSV: "** **.** **trim($results);** **// We trim to remove extra linebreaks and spaces**   **}}** **else** **{** **// if there was a connection error**   **// print error**   **echo** **"Connection error!";}**?**\>**

- [Above.com Help Guides](https://support.above.com/above-com-help-guides?hsLang=en)
- [Monetization FAQs](https://support.above.com/monetization-faqs?hsLang=en#main-content)

    - [Getting Started](https://support.above.com/monetization-faqs?hsLang=en#getting-started)
    - [Above Maximizer](https://support.above.com/monetization-faqs?hsLang=en#above-maximizer)
    - [Account Maintenance](https://support.above.com/monetization-faqs?hsLang=en#account-maintenance)
    - [Getting Paid](https://support.above.com/monetization-faqs?hsLang=en#getting-paid)
    - [Stats and Reports](https://support.above.com/monetization-faqs?hsLang=en#stats-and-reports)
    - [Monetization & Portfolio Manager API](https://support.above.com/monetization-faqs?hsLang=en#monetization-portfolio-manager-api)
    - [Other Questions](https://support.above.com/monetization-faqs?hsLang=en#other-questions)
- [Marketplace FAQs](https://support.above.com/marketplace-faqs?hsLang=en#main-content)

    - [Selling](https://support.above.com/marketplace-faqs?hsLang=en#selling)
    - [Buying](https://support.above.com/marketplace-faqs?hsLang=en#buying)
    - [Other](https://support.above.com/marketplace-faqs?hsLang=en#other)
- [Registrar FAQs](https://support.above.com/registrar-faqs?hsLang=en#main-content)

    - [Registration](https://support.above.com/registrar-faqs?hsLang=en#registration)
    - [Transfer](https://support.above.com/registrar-faqs?hsLang=en#transfer)
    - [DNS](https://support.above.com/registrar-faqs?hsLang=en#dns)
    - [Verification](https://support.above.com/registrar-faqs?hsLang=en#verification)
    - [Two Step Authentication](https://support.above.com/registrar-faqs?hsLang=en#two-step-authentication)
    - [API](https://support.above.com/registrar-faqs?hsLang=en#api)
    - [Other](https://support.above.com/registrar-faqs?hsLang=en#other)
- [Portfolio Manager FAQs](https://support.above.com/portfolio-manager-faqs?hsLang=en#main-content)

    - [Features](https://support.above.com/portfolio-manager-faqs?hsLang=en#features)
    - [Account Maintenance](https://support.above.com/portfolio-manager-faqs?hsLang=en#account-maintenance)
    - [Stats and Reports](https://support.above.com/portfolio-manager-faqs?hsLang=en#stats-and-reports)
    - [Monetization & Portfolio Manager API](https://support.above.com/portfolio-manager-faqs?hsLang=en#monetization-portfolio-manager-api)
    - [Domain Consolidate](https://support.above.com/portfolio-manager-faqs?hsLang=en#domain-consolidate)
    - [Other](https://support.above.com/portfolio-manager-faqs?hsLang=en#other)
- [Portfolio Manager Manual](https://support.above.com/portfolio-manager-manual?hsLang=en#main-content)

    - [Introduction](https://support.above.com/portfolio-manager-manual?hsLang=en#introduction)
    - [Interface](https://support.above.com/portfolio-manager-manual?hsLang=en#interface)
    - [Portfolio Manager](https://support.above.com/portfolio-manager-manual?hsLang=en#portfolio-manager)
    - [Sell Domains](https://support.above.com/portfolio-manager-manual?hsLang=en#sell-domains)
    - [Offers Received](https://support.above.com/portfolio-manager-manual?hsLang=en#offers-received)
    - [Registrar](https://support.above.com/portfolio-manager-manual?hsLang=en#registrar)
    - [Monetization API](https://support.above.com/portfolio-manager-manual?hsLang=en#monetization-api)
    - [Registrar API](https://support.above.com/portfolio-manager-manual?hsLang=en#registrar-api)
    - [My Account Manual](https://support.above.com/portfolio-manager-manual?hsLang=en#my-account-manual)
    - [Column Descriptions](https://support.above.com/portfolio-manager-manual?hsLang=en#column-descriptions)
    - [Domain Details](https://support.above.com/portfolio-manager-manual?hsLang=en#domain-details)
    - [Supported Domains (TLDs)](https://support.above.com/portfolio-manager-manual?hsLang=en#supported-domains-tlds)
    - [Support and Help](https://support.above.com/portfolio-manager-manual?hsLang=en#support-and-help)
- [Monetization Quick-Start Guide](https://support.above.com/monetization-quick-start-guide?hsLang=en)

[![Above.com Logo](https://support.above.com/hs-fs/hubfs/above-logo-466.png?width=466&height=88&name=above-logo-466.png "Above.com Logo")](https://www.above.com)

<https://www.facebook.com/> <https://www.twitter.com/> <https://www.instagram.com/> <https://podcasts.apple.com/> [mailto:email@email.com](mailto:email@email.com)

Copyright © 2026, Trillion Pty Ltd

 Domain Registrar

[Register Domains](https://www.above.com/registrar/index.html)

[Pricing](https://www.above.com/registrar/domain-pricing.html)

[FAQs](https://www.above.com/registrar/faq.html)

[Dispute Policy](https://www.above.com/registrar/domain-dispute-policy.html)

[Terms of Service](https://www.above.com/terms-of-service.html#Above.com_Registrar_Terms)

[WHOIS](https://www.above.com/registrar/whois.html)

 Marketplace

[Sell My Domains](https://www.above.com/sell-my-domains.html)

[Buy Domains](https://www.above.com/marketplace/index.html)

[Escrow](https://www.above.com/marketplace/escrow.html)

[FAQs](https://www.above.com/marketplace/faq.html)

[Terms of Service](https://www.above.com/terms-of-service.html#Above.com_Marketplace_Terms)

 Monetization

[Monetization](https://www.above.com/monetization.html)

[Reporting](https://www.above.com/reporting.html)

[FAQs](https://www.above.com/faq.html)

[Terms of Service](https://www.above.com/terms-of-service.html#Above.com_MAP_Terms)

 Brokerage

[Domain Brokerage](https://www.above.com/domain-brokerage.html)

[Sell a Domain](https://www.above.com/domain-brokerage.html#sell-domain)

[Buy a Domain](https://www.above.com/domain-brokerage.html#buy-domain)

[How It Works](https://www.above.com/domain-brokerage.html#how-it-works)

[Meet the Brokers](https://www.above.com/domain-brokerage.html#broker-team)

 Above/Support

[Contact Us](https://www.above.com/contact.html)

[About Us](https://www.above.com/about.html)

[Our Team](https://www.above.com/our-team.html)

[Above & Beyond Club](https://www.above.com/above-beyond-club.html)

[Careers](https://www.trillion.com/careers.html)

[Blog](https://www.above.com/blog/)

[Site Map](https://www.above.com/sitemap.html)

Socials

<https://www.linkedin.com/company/abovedomain/>

[LinkedIn](https://www.linkedin.com/company/abovedomain/)

<https://twitter.com/above_domain>

[X.com](https://twitter.com/above_domain)

<https://www.facebook.com/above.domain>

[Facebook](https://www.facebook.com/above.domain)

<https://www.instagram.com/above_com>

[Instagram](https://www.instagram.com/above_com)

Accreditations

- ![](https://www.above.com/img/icann_logo.png)
- ![](https://www.above.com/img/auda-logo-black.png)
- ![](https://www.above.com//img/iso_black.png)

 Copyright © 2008 -  Above.com Pty Ltd - All rights reserved. [Privacy Policy](https://www.above.com/privacy-policy.html)