1

I have been able so far to create a new civi Mailing object and populate it, but confusingly I can't see a parameter in that to specify the mail destination group.

For context, I am dealing with Civi using pure REST api from a remote server. I have a solution to getting a custom template onto the server; the new problem is setting a schedule and delivery group, and initiating the send. I am using the python-civicrm library from github as the intermediary on the client.

I presume send happens as a result of setting the schedule -- i.e. I don't need an API call to say 'send mailing'? Is setting 'sheduled date' == 'now' safe or should I set a date of 'now + 1min' or similar?

So that leaves setting the delivery group. We already have groups defined in the DB, and I want to specify the group by name (and preferably be able to verify in advance that a group name is a valid destination, perhaps by doing a group name -> id lookup).

I think there might be a parameter to Mailing create 'groups' which can have keys 'include' and 'exclude'; at least, that's what the web form seems to do. However it's not mentioned in the REST api implementation.

Can anyone offer pointers?

rivimey
  • 921
  • 1
  • 7
  • 24
  • Please consider supporting the CiviCRM stack exchange project by committing to http://area51.stackexchange.com/proposals/77367/civicrm and linking to your others SE account : http://discuss.area51.stackexchange.com/questions/18465/please-link-your-other-se-accounts – samuelsov Feb 02 '15 at 14:35

2 Answers2

1

I think you will find all you need in the following link :

Otherwise, if it doesn't work, i suggest that you :

The table you need to check in the database is civicrm_mailing_group

samuelsov
  • 395
  • 2
  • 10
  • Thanks samuelsov, I hadn't noticed the gist which is helpful, though I had seen the thread. Sadly, my initial attempt at setting the groups/include parameter wasn't successful, so I'm going in with the debugger on the Civi side to see what's going on. – rivimey Feb 04 '15 at 10:14
  • The problem I'm seeing is that the structure groups[include] = array(id) is transformed into groups=include when the parameters are transformed into the HTTP POST request (in my case, by the Python requests module). Thus the group id never reaches Civi. – rivimey Feb 04 '15 at 11:59
  • Not sure about that, but when playing with api explorer at http://yourwebsite.org/civicrm/api/explorer, the proposed syntax use json so something like : /sites/all/modules/contrib/civicrm/extern/rest.php?entity=Mailing&action=create&json={"name":"the name","subject":"the subject","groups.include":[10,11]}&api_key=yoursitekey&key=yourkey – samuelsov Feb 05 '15 at 14:23
1

To confirm, the problem was that (a) I needed to use groups[include]=array(ids) as mentioned by samuelsov, but also (b) I needed to use the json={...} form of request through REST, because the HTTP params syntax doesn't support nested data.

rivimey
  • 921
  • 1
  • 7
  • 24