Services require administrator privileges to access. The token service should be enabled (default installation).
To List Available Services
Listing services requires the GET method and the URL.
httpRequest.open("GET", "/fmerest/services.json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
var reply = eval("(" + httpRequest.responseText + ")");
if (typeof(reply.serviceResponse.services.service) != 'undefined')
{
var resources = reply.serviceResponse.services.service;
for (var i in resources)
{
println(resources[i].name);
}
}
else
{
println("No Resources Found");
}
}
else
{
println("Error");
}
}
}
httpRequest.send(null);
To Add Services
To add a service, the service name, service display name, description and URL pattern are required. If there is an existing service with the same name, it is replaced.
httpRequest.open("POST", "/fmerest/services.json?token="+token_, true);
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var param = "service="+name;
param += "&description="+description;
param += "&displayname="+displayName;
param += "&urlpattern="+urlPattern;
param += "&isenabled=true";
param += "&isregallowed=true";
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
println("Service added");
}
else
{
println("Failed to add service");
}
}
}
httpRequest.send(param);
To Remove Services
To remove a service, the service name is required.
httpRequest.open("DELETE", "/fmerest/services/"+name+".json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
println("Service removed");
}
else
{
println("Failed to remove service");
}
}
}
httpRequest.send(null);