Archive

Posts Tagged ‘rules’

SWS GetSiteRules Method

April 20, 2011 1 comment

Retrieves all site rules if using just the SiteID or all information for the specified rule if including the RuleID.

Parameters

Name DataType Is Required
Active Boolean Optional
Description Applies a filter for rules that are set to active (“True”) or not (“False”).
RuleID Long Optional
Description The rule’s ID number in the system.
SiteID Long Required
Description The site’s ID number. This can be found using the GetSiteList method.

Returned Parameters

Name DataType
RULE_VALUES RULE_VALUES
Description The object containing all the information about the rule/rules.

Example

As with every method we need to pass in credentials. We do this with the LookupUser request object.

We’ll assume you’ve got a web reference, let’s name it SWS, in your Visual Studio project.  At this point we need to our objects.  We’ll need the standard service object, a GetSiteRules request object and a GetSiteRules response object. We can define and create those like this:

// Create a request and response objects
SWS.WSSoapClient service = new SWS.WSSoapClient();
SWS.Rules_Request request = new SWS.Rules_Request();
SWS.GetSiteRules_Response response;

Here’s my sample code of the Request object to all pull rules for a site. Optional parameters are available to further narrow results.

// GetSiteRules Request
request.SiteID = 123456;

Finally we can call the method and pass across the login object and the request object to get our site rules. It’s a good idea to do this in a Try Catch block.

// Call the method that will load the response object
try
{
  response = service.GetSiteRules(user_request, request);
}
catch (Exception ex)
{
  MessageBox.Show(ex.Message);
}

Note that if something goes wrong the service will respond with an exception. You’ll want to take a look at that message returned in that exception so it can be debugged.
For a full list of methods see SWS Methods.