Need HELP about decoding cpanel's JSON

Erratic Stuff

Registered
Oct 27, 2020
4
0
1
IDK
cPanel Access Level
Website Owner
Hello,
I'm confused about how to get the value of cPanel JSON's via PHP
(If it's possible please bring back the XML's API)
Please help me,
Code :

PHP:
<?php
$json = '{
   "metadata":{
      "version":1,
      "command":"get_domain_info",
      "result":1,
      "reason":"OK"
   },
   "data":{
      "domains":[
        {
          "docroot":"/home/user1/public_html/example.com",
          "domain":"example.com",
          "domain_type":"addon",
          "ipv4":"192.0.2.255",
          "ipv4_ssl":"192.0.2.255",
          "ipv6":"2001:DB8:g1m:0N3y:1",
          "ipv6_is_dedicated":1,
          "modsecurity_enabled":1,
          "parent_domain":"example.com",
          "php_version":"ea-php54",
          "port":80,
          "port_ssl":443,
          "user":"username",
          "user_owner":"user1"
        }
      ]
   }
}';
$array = json_decode($json, true);
echo $array['ipv4'];
?>
Result :
1605850786350.png
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
2,251
300
213
cPanel Access Level
Root Administrator
Hey there, @Erratic Stuff !

I believe this example is what you're looking for, but let me know if that doesn't clear things up!