Connect. Communicate. Collaborate. Securely.

Home » Developer Zone » API/SDK Writers » Set custom spam rule list
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
I took the "example.php" and added

$params = array(
'enabled' => 1,
'header' => 'To',
'content' => 'ralph<_at_>aplawrence.com',
'description' => 'Ralph Rule',
'type' => 2,
'action' => 3,
'score' => 20,
'lastUsed' => null,
'isOrderChanged' => 0);

$result = $Api->sendRequest('Content.setCustomRuleList',$params);


I get

Success. You are logged in as Administrator using the Administration API.
Invalid params.

I believe it - what didn't I understand here?


[Updated on: Thu, 03 May 2012 08:56] by Moderator


Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
To perhaps be more explicit, what did I do wrong in the params?

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Lukas Nemec

Messages: 33
Karma: 0
Send a private message to this user
Hi,

if you need to add new custom rules you need to send the whole collection of existing custom rules plus a new one. Spam filter custom rules respect the order, the order is defined in the request params rules order. Each rule is defined as an array.

Please, try following:

$params = array(array(
<already defined rule1>
),
array(
'enabled' => 1,
'header' => 'To',
'content' => 'ralph<_at_>aplawrence.com',
'description' => 'Ralph Rule',
'type' => 2,
'action' => 3,
'score' => 20,
'lastUsed' => null
),
array(
<already defined rule2>
));

$result = $Api->sendRequest('Content.setCustomRuleList',$params);


Is it understandable? Don't hesitate to ask for any help with Administration API.

Cheers,

Lukas Nemec
WebAdmin developer
Kerio Technologies
.............................................
Connect. Communicate. Collaborate. Securely.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Ahh.. that makes sense!

Thanks!

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
OK, so first I have to get all the rules and then add or splice in my new rule.

In the SearchQuery: is "empty" null or literally empty: "" ?

If "fields" and "conditions" are empty, does "combining" matter at all?

For all rules, "start" would be 0 and "limit" set to Unlimited.. orderby doesn't matter for this?

00132 struct SearchQuery {
00133 StringList fields; ///< empty = give me all fields, applicable constants: ADD_USERS, LIST_USERS
00134 SubConditionList conditions; ///< empty = without condition
00135 LogicalOperator combining; ///< the list of conditions can be either combined by 'ORs' or 'ANDs'
00136 long start; ///< how many items to skip before filling a result list (0 means skip none)
00137 long limit; ///< how many items to put to a result list (if there are enough items); applicable constant: Unlimited
00138 SortOrderList orderBy;

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Anonymous
Karma:
Quote:

In the SearchQuery: is "empty" null or literally empty: "" ?


Just omit it completely.

Quote:

If "fields" and "conditions" are empty, does "combining" matter at all?


combining only applies on conditions. If conditions are omitted, combining is ignored.

Quote:

For all rules, "start" would be 0 and "limit" set to Unlimited.. orderby doesn't matter for this?


Orderby does not make sense and thus is not implemented in this particular case.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Then that sounds like all I need to reference is "start" and "limit" ? Just leave the rest out?

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Anonymous
Karma:
pcunix wrote on Mon, 30 April 2012 17:29
Then that sounds like all I need to reference is "start" and "limit" ? Just leave the rest out?


Yes, in this case.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
So what am I supposed to pass to getCustomRuleList ? The first parameter is an array - an empty array? Am I supposed to sen that? I wouldn't think so, but when I try this I end up with something like

{"jsonrpc":"2.0","id":4,"token":" 986cc167e0075cc0f679d0f362072da8a111b4081de2cba415b386ada1bd eab1 ","method":"Content:getCustomRuleList","params":{"query ":{"start":0,"limit":10}}}


{"jsonrpc":"2.0","id":4,"error":{"code":-32600,"message ":"Invalid request.","data":{"messageParameters":{"positionalParameters ":[],"plurality":1}}}}

[Updated on: Mon, 30 April 2012 21:03]


Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Anonymous
Karma:
Could you please send us your request?
  •  
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
Hello Tony,
please notice a small typo in your request.

pcunix wrote on Mon, 30 April 2012 19:55
{"jsonrpc":"2.0","id":4,"token":" 986cc167e0075cc0f679d0f362072da8a111b4081de2cba415b386ada1bd eab1 ","method":"Content:getCustomRuleList","params":{"query ":{"start":0,"limit":10}}}


There should be Content.getCustomRuleList because requested method is a conjunction of an Interface (e.g. Content) and its method (e.g. getCustomRuleList) joined by a dot.

I.e. Interface.method

Just for demonstration, what you see in Web Administration is defined by a JSON request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "Content.getCustomRuleList",
  "params": {
    "query": {
      "conditions": [
        {
          "fieldName": "description",
          "comparator": "Like",
          "value": ""
        }
      ],
      "combining": "And",
      "limit": -1,
      "fields": [
        "id",
        "enabled",
        "header",
        "kind",
        "type",
        "content",
        "action",
        "description",
        "lastUsed",
        "score"
      ]
    }
  }
}


Is it helpful for you? Do you need more assistance how to translate it to a request in PHP?

Best regards,

Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Yes, that was it..

Is there any syntax checker for this stuff like "perl -c"?

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
There ain't no such thing but it's a quite interesting idea ... Smile

Best regards,

Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
  •  
Anonymous
Karma:
pcunix wrote on Wed, 02 May 2012 12:03
Yes, that was it..

Is there any syntax checker for this stuff like "perl -c"?


I personally use jsonizer to check JSON. It is buggy and available for Win only but useful. Nevertheless, it is only a formal syntax checker. Unfortunatelly I don't have a tool which could also check according provided IDL files...
Miroslav Osladil (Kerio)

Messages: 188

Karma: 27
Send a private message to this user
pcunix wrote on Tue, 24 April 2012 00:00
...


For better navigation, I changed the title for easier search in the future.

Thanks for understanding.

Miroslav Osladil
Senior Developer
Kerio Technologies

The views I express are my own and do not necessarily reflect the views of Kerio Technologies.
Previous Topic: How to share code I've written
Next Topic: Create domains in API
Goto Forum:
  


Disclaimer:
Kerio discussion forums are intended for open communication between forum members and may contain information and material posted by members which may be useful in learning about Kerio products. The discussion forums are not intended to provide technical support for any specific product. Any information implied or expressed in the discussion forums is that of the posting member. Kerio is in no way responsible for the information posted in the forums, or its accuracy. Kerio employees may participate in the discussions, but their postings do not represent an offical position of the company on any issues raised or discussed. Kerio reserves the right to monitor and maintain the forums to promote free and accurate exchange of information.

Current Time: Fri Oct 20 08:51:33 CEST 2017

Total time taken to generate the page: 0.00496 seconds
.:: Contact :: Home ::.
Powered by: FUDforum 3.0.4.