In Progress CPANEL-40803 - How to use cURL for UAPI store_filter to create email filter

Indinfer

Active Member
Mar 25, 2018
26
3
53
Baltimore, Maryland
cPanel Access Level
Website Owner
I am looking at Create email filter · cPanel & WHM Developer Portal . This problem is a one-line Windows batch file.

First, I see an error in the documentation URL example. The example is:
https://hostname.example.com:2083/cpsess##########/execute/Email/store_filter&filtername=coffee&action%2a=deliver&match%2a=contains&part%2a=%24header_from&val%2a=coconut

There is no ? in the example line. The first & should be ? .

I figured out from the error message saying something about "illegal function name." When I changed the first & to ? the error changed to "No valid rules."
Therefore, I think my problem is I don't know how to express a valid rule for this cPanel function.

I am afraid maybe the documentation for this function may be incorrect in other ways besides the example above. Or, I am just not smart enough to figure it out independently. And therefore, I will certainly appreciate some help.

I have successfully used the UAPI to create an email address, delete an email address, get an email quota, and return a list of email accounts for the domain. But create email filter is more complicated for me.

Here is what I am doing in a Windows batch file:

cURL -H "Authorization: cpanel indinferaem:[token]" "https://assigned-email-manager.com:2083/execute/Email/store_filter?filtername=redirect&action*=deliver&match*=contains&part*=$header_to&val*=jerry&[email protected]&dest*[email protected]"

This is supposed to redirect mail from jerry to gerry. However, I get this error, "No valid rules."

The response is {"warnings":null,"data":null,"errors":["No valid rules."],"metadata":{},"status":0,"messages":null}

I also tried substituting %2a for *, and %24 for $ . But I get the same error.

I hope somebody can help me figure this function out.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
17,470
2,843
363
cPanel Access Level
Root Administrator
I'm also not able to get that API call to work properly with the details provided on that page so I've created case CPANEL-40803 for our developers to look into this. I'll be sure to post back to this thread once I have an update.
 

Indinfer

Active Member
Mar 25, 2018
26
3
53
Baltimore, Maryland
cPanel Access Level
Website Owner
The following worked:

cURL -H "Authorization: cpanel indinferaem:[token]" "https://assigned-email-manager.com:2083/execute/Email/store_filter?filtername=redirect&action1=deliver&match1=contains&part1=$header_to:&val1=jerry&[email protected]&[email protected]"

I got these results:

{"metadata":{},"errors":null,"messages":null,"data":{"account":"[email protected]"},"status":1,"warnings":null}

I went into the cPanel GUI and verified that the filter was indeed created.

I think cURL automatically changes illegal URL characters into % codes. That's why I could use @ for asterisk and : for colon, etc.

I think that my issue could be a documentation issue. Maybe the documentation would be easier to understand if there was a note to replace the * with a number. There could be a note in the documentation to include the : . And the URL example needs to have a question mark. Of course, I don't know how it is supposed to work. Still, explaining the * would make the documentation match how it works now.

The cPanel team probably will come up with something better than my suggestion. That's a big reason I am trying to use cPanel to make my application work.