Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

How to filter cPanel API 2 ?

Discussion in 'cPanel Developers' started by Killy123, Oct 28, 2016.

Tags:
  1. Killy123

    Killy123 Member

    Joined:
    Oct 28, 2016
    Messages:
    18
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    I am sending the following post request to the api
    Code:
    json-api/cpanel?cpanel_jsonapi_user=andreytestdom&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=AddonDomain&cpanel_jsonapi_func=listaddondomains&api2_filter=1&api_filter_column_0=subdomain&api_filter_term_0=andreytest134&api2_filter_type_0=contains
    And the results are NOT filtered. I am getting :
    Code:
    {
      "cpanelresult": {
        "data": [
          {
            "basedir": "andreytest134.eu",
            "fullsubdomain": "andreytest134.andreytestdom.com",
            "subdomain": "andreytest134",
            "dir": "/var/home/andreytestdom/andreytest134.eu",
            "domain": "andreytest134.eu",
            "reldir": "home:andreytest134.eu",
            "rootdomain": "andreytestdom.com",
            "status": "not redirected",
            "domainkey": "andreytest134_andreytestdom.com"
          },
          {
            "dir": "/var/home/andreytestdom/newTestApiDomain.com",
            "subdomain": "newtestapidomain",
            "fullsubdomain": "newtestapidomain.andreytestdom.com",
            "basedir": "newTestApiDomain.com",
            "reldir": "home:newTestApiDomain.com",
            "domain": "newtestapidomain.com",
            "rootdomain": "andreytestdom.com",
            "domainkey": "newtestapidomain_andreytestdom.com",
            "status": "not redirected"
          }
        ],
        "module": "AddonDomain",
        "event": {
          "result": 1
        },
        "func": "listaddondomains",
        "apiversion": 2,
        "records_before_filter": 2
      }
    }
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Killy123,

    The filter variables for cPanel API 2 should all begin with "api2". Try updating your example to the following:

    Code:
    json-api/cpanel?cpanel_jsonapi_user=andreytestdom&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=AddonDomain&cpanel_jsonapi_func=listaddondomains&api2_filter=1&api2_filter_column_0=subdomain&api2_filter_term_0=andreytest134&api2_filter_type_0=contains
    Let us know if this helps.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Killy123

    Killy123 Member

    Joined:
    Oct 28, 2016
    Messages:
    18
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    Thanks for your answer, but I still get empty data object:
    Code:
    {
      "cpanelresult": {
        "event": {
          "result": 1
        },
        "records_before_filter": 3,
        "module": "AddonDomain",
        "func": "listaddondomains",
        "data": [],
        "apiversion": 2
      }
    }
    This is the request I made :
    Code:
    json-api/cpanel?cpanel_jsonapi_user=andreytestdom&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=AddonDomain&cpanel_jsonapi_func=listaddondomains&api2_filter=1&api2_filter_column_0=domain&api2_filter_term_0=newtestapidomain.com &api2_filter_type_0=contains
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    I've verified this is working on cPanel version 58 and cPanel version 60. Here's the exact URL I entered after creating xyz.tld as an addon domain name under the account:

    Code:
    https://1.2.3.4:2083/cpsess123456789/json-api/cpanel?cpanel_jsonapi_user=cptest01&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=AddonDomain&cpanel_jsonapi_func=listaddondomains&api2_filter=1&api2_filter_column=domain&api2_filter_term=xyz.tld&api2_filter_type=contains
    Try using the code in this example, as it looks like the example you posted used a space after the domain name. I also removed the filter numerical values, as you are not using multiple filters in this scenario.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Killy123

    Killy123 Member

    Joined:
    Oct 28, 2016
    Messages:
    18
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    I tried everything you said, but the api still returns:
    Code:
    {
      "cpanelresult": {
        "apiversion": 2,
        "func": "listaddondomains",
        "records_before_filter": 3,
        "data": [],
        "module": "AddonDomain",
        "event": {
          "result": 1
        }
      }
    }
     
  6. Killy123

    Killy123 Member

    Joined:
    Oct 28, 2016
    Messages:
    18
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    I ran into another problem, when I am sending a request to delete an Addondomain I am sending :
    Code:
    /json-api/cpanel?cpanel_jsonapi_user=andreytestdom&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=AddonDomain&cpanel_jsonapi_func=deladdondomain&domain=addondomain.com&subdomain=addondomain_example.com
    And I get :
    Code:
    {
      "cpanelresult": {
        "data": [
          {
            "result": 0,
            "reason": "You do not have control of the subdomain for “addondomain.com”.\n"
          }
        ],
        "module": "AddonDomain",
        "event": {
          "result": 1
        },
        "apiversion": 2,
        "func": "deladdondomain",
        "error": "You do not have control of the subdomain for “addondomain.com”.\n"
      }
    }
     
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Could you open a support ticket using the link in my signature so we can take a closer look? You can post the ticket number here and I will update this thread with the outcome.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice