• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.

Question Using curl to get a specific value from Remote API (REST)

stevland

Basic Pleskian
Server operating system version
CentOS Linux 7.9.2009 (Core)
Plesk version and microupdate number
Plesk Obsidian Version 18.0.51
I use curl to get a DNS record from my Plesk server:

Code:
curl -X GET -H 'authorization: Basic xxx' -H 'accept: application/json' 'https://example.com:8443/api/v2/dns/records/15781/'

result:

Code:
{
    "id": 15781,
    "type": "A",
    "host": "home.example.com",
    "value": "123.123.123.123",
    "opt": "",
    "ttl": 600
}

But what if I only want 123.123.123.123?
 
Step by step:

Code:
# curl -X GET -H 'authorization: Basic xxx' -H 'accept: application/json' 'https://example.com:8443/api/v2/dns/records/15781/' > output.txt
# grep value output.txt | awk -F '"' '{print $4}'
# rm -F output.txt

or in one line (not tested):

Code:
# curl -X GET -H 'authorization: Basic xxx' -H 'accept: application/json' 'https://example.com:8443/api/v2/dns/records/15781/' 2>&1 | grep value | awk -F '"' '{print $4}'
 
Back
Top