REST API Examples

REST API Examples

This article provides a few examples on how to use the Barracuda Web Application Firewall REST APIs:

In this article:

Virtual Service

Real Server

Content Rule

Rule Group Server

Logs

Certificates

Virtual Service

To Create a Virtual Service
Example: Creating a HTTP Service

Request:


curl -X POST "http://10.36.73.160:8000/restapi/v3.2/services " -H "Content-Type: application/json" -u "eyJldCI6IiOGUxNDQ2OTM4ZjRkIn0=\n:" -d
{
"address-version": "IPv4",
"app-id": "app1",
"comments": "This is a demo service",
"ip-address": "10.36.73.154",
"mask": "255.255.255.0",
"name": "service_app1",
"port": "80",
"type": "HTTP"
}

Response:

{"id":"service_app1","token":"eyJ1c2ZXQiOiIxNjI2MDg1NDc3In0=\n","msg":"Successfully created."}

Example: Creating a HTTPS Service

Request:

curl -X POST "http://10.36.73.160:8000/restapi/v3.2/services " -H "Content-Type: application/json" -u "eyJldCkNjQzNjZiOGUxNDQ2OTM4ZjRkIn0=\n:" -d
'{

"address-version": "IPv4",
"app-id": "app1-https",
"comments": "This is a demo service",
"ip-address": "10.36.73.154",
"mask": "255.255.255.0",
"name": "service_app1_secure",
"port": "443",
"certificate": "test_cert",
"type": "HTTPS"
}'

Response:

{"id":"service_app1_secure","token":"eyJldCNlciI6ImFkbWluIn0=\n","msg":"Successfully created."}

To Retrieve a Virtual Service
Example:

Request:

curl -X GET "http://10.36.73.160:8000/restapi/v3.2/services/service_app1" -H "Content-Type: application/json" -u "eyJldCI6IjE2xNDQ2OTM4ZjRkIn0=\n:"

Response:

{
"data": {
"service_app1": {
"Captcha Settings": {
"recaptcha-domain": [

],
"recaptcha-type": "CAPTCHA"
},
"Instant SSL": {
"status": "Off",
"sharepoint-rewrite-support": "Off",
"secure-site-domain": [

]
},
"SSL OCSP": {
"responder-url": "",
"certificate": "",
"enable": "No"
},
"WaaS Account Details": {
"waas-account-id": "0",
"waas-account-serial": "1623473"
},
"Server": {

},
"mask": "255.255.255.255",
"type": "HTTP",
"session-timeout": "60",
"Caching": {
"status": "Off",
"ignore-request-headers": "No",
"cache-negative-response": "No",
"file-extensions": [

],
"ignore-response-headers": "No",
"min-size": "256",
"expiry-age": "60",
"max-size": "256"
},
"Comment Spam": {
"exception-patterns": [

],
"parameter": [

]
},
"ip-address": "10.36.73.154",
"Rule Group": {

},
"vsite": "default",
"status": "On"....."rate-control-pool": "NONE",
"mode": "Passive",
"web-firewall-policy": "default",
"client-ip-addr-header": "",
"trusted-hosts-group": "",
"trusted-hosts-action": "Default"
}
}
},
"object": "Service",
"token": "eyJ1c2VQiOiIxNjI2MDg1ODkyIn0=\n"
}

(The above response is snipped)

To Update a Virtual Service

In this REST API call, the parameters can be passed in a Simple JSON request or a Nested JSON request based on the parameters that needs to be modified. For information on JSON requests, see Request Syntax.

Example:

Request:

curl -X PUT "http://10.36.73.160:8000/restapi/v3.2/services/service_app1 " -H "Content-Type: application/json" -u "eyJldCI6IjGUxNDQ2OTM4ZjRkIn0=\n:" -d '{"enable-access-logs": "Yes"}'

Response:

{"id":"service_app1","msg":"Configuration updated","token":"eyJldCI6YjdiOTgzNjExIn0=\n"}

To Delete a Virtual Service
Example:

Request:

curl -X DELETE "http://10.36.73.160:8000/restapi/v3.2/services/service_app1" -u "eyJwYXNzQiOiIxNjI2MDg5NjcwIn0=\n:"

Response:

{"token":"eyJldCI6IjE2MiI6ImFkbWluIn0=\n","msg":"Successfully deleted."}

Real Server

To Create a Real Server
Example:

Request:

curl -X POST "http://10.36.73.160:8000/restapi/v3.2/services/service_app1/servers " -H "Content-Type: application/json" -u "eyJldCI6IjNDQ2OTM4ZjRkIn0=\n:" -d

'{
"ip-address": "10.1.1.1",
"name": "real_server_1",
"identifier": "IP Address",
"port": "80",
"address-version": "IPv4",
"comments": "Real Server"
}'

Response:

{"msg":"Successfully created.","token":"eyJ1c2VyNjI2MDg3ODE5In0=\n","id":"real_server_1"}

To Retrieve all Real Servers for a Service
Example:

Request:

curl -X GET "http://10.36.73.160:8000/restapi/v3.2/services/service_app1/servers " -u "eyJldCUxNDQ2OTM4ZjRkIn0=\n:"

Response:

{
"data": {
"real_server_1": {
"Out of Band Health Checks": {
"interval": "10",
"enable-oob-health-checks": "Yes"
},
"Load Balancing": {
"backup-server": "No",
"weight": "1"
},
"hostname": "",
"name": "real_server_1",
"ip-address": "10.1.1.1",
"identifier": "IP Address",
"port": "80",
"status": "In Service",
"Advanced Configuration": {
"max-spare-connections": "0",
"timeout": "300000",
"max-establishing-connections": "100",
"max-requests": "1000",
"source-ip-to-connect": "",
"max-keepalive-requests": "0",
"max-connections": "10000",
"client-impersonation": "No"
},
"SSL Policy": {
"enable-ssl-compatibility-mode": "No",
"validate-certificate": "Yes",
"enable-https": "No",
"enable-tls-1": "No",
"enable-ssl-3": "No",
"enable-tls-1-3": "No",
"enable-tls-1-1": "Yes",
"enable-http2-server": "No",
"client-certificate": "",
"enable-sni": "No",
"enable-tls-1-2": "Yes"
},
"Application Layer Health Checks": {
"method": "GET",
"url": "",
"status-code": "200",
"match-content-string": "",
"domain": "",
"additional-headers": [

]
},
"In Band Health Checks": {
"max-timeout-failure": "10",
"max-other-failure": "10",
"max-http-errors": "0",
"max-refused": "10"
},
"Connection Pooling": {
"enable-connection-pooling": "Yes",
"keepalive-timeout": "900000"
},
"address-version": "IPv4",
"resolved-ips": "",
"comments": "Real Server"
}
},
"object": "Server",
"token": "eyJldCI62MTRlZjQ1ZTEzIn0=\n",
"Service": "service_app1"
}

To Update a Real Server
Example:

Request:

curl -X PUT "http://10.36.73.160:8000/restapi/v3.2/services/service_app1/servers/real_server_1 " -H "Content-Type: application/json" -u "eyJldCI6IQTM4ZjRkIn0=\n:" -d '{ "status": "Out of Service Maintenance" }'

Response:

{"token":"eyJldCI6IjEZjQ2YTFkIn0=\n","msg":"Configuration updated","id":"real_server_1"}

To Delete a Real Server

Content Rule

To Create a Content Rule
To Retrieve a Content Rule
To Update a Content Rule
To Delete a Content Rule

Rule Group Server

To Create a Rule Group Server
To Retrieve a Rule Group Server
To Update a Rule Group Server
To Delete a Rule Group Server

Logs

The maximum number of logs that can be fetched at a time using Logs REST API is 1,00,000.

To Fetch Logs

By default, 20 logs are fetched at a time.