Posting via API does not send email notification

Hello,

In my setup:

  • mailgun is set up, posting manually works, publish send by email manually works (subscriber notifications are generated and sent)
  • posting via API works
  • but posting via API does not generate subscriber notifications

Am I missing some argument or some setting?

Thanks!

What version of Ghost are you using?
Can you include an example of how you’re communicating with the API? Which params you’re passing etc…

Yes, ghost v3, using python

url = 'https://<someblog>/ghost/api/v3/admin/posts/' ## edited

	body = {
		"posts": [{
		"title": "api test html table",
		"custom_excerpt": "excerpt - api test",
		"tags": ["api-post"],
		"authors": [<some@email>], ## edited
		"visibility": "members",
		#"status": "published", ## published publishes, but no email
		#"send_email_when_published": True, ## no effect?
		"mobiledoc": mdoc,
		}]
	}
	r = requests.post(url, json=body, headers=headers)

BTW I can create the same post as draft successfully with the API
Then publish the draft & send by email manually works and generates the emails

How can I automate this?

I can also publish the draft via API (GET, then PUT status=published), but still no emails…

OK. So there is a workaround, not sure this is documented

First post a draft, then publish the draft in a second transaction, and set argument send_email_when_published

...
	r = requests.post(url, json=body, headers=headers)

	body = json.loads(r.content)
	post_id = body['posts'][0]['id']
	
	time.sleep(1)
	
	url = 'https://<someblog>/ghost/api/v3/admin/posts/'+post_id+'/?send_email_when_published=all'
	body['posts'][0]['status'] = 'published'
	body['posts'][0]['send_email_when_published'] = 'all' ## i think this is ignored
	
	r = requests.put(url, json=body, headers=headers)

@os72 immediate publishing of a post via email needs to be done via a query param, POST .../posts/?send_email_when_published=true. Note that all API’s around the members beta feature are experimental and are subject to change without notice.

Thanks @Kevin,

I tried POST w the parameter again, it’s not working for me (ghost 3.37.1). For some reason it needs the 2 transactions. (Value true or all doesn’t seem to matter) I wonder if the code somewhere looks at the transition from draft to published to trigger this

Re API, yes I saw this one in progress ( email_recipient_filter): https://github.com/TryGhost/Ghost/pull/12343

When is this part of the API expected to stabilize?

:frowning: sorry for pointing you down the wrong path! The code was intended to work with POSTs but an omission meant that it only works with PUTs

For now I think you’ll have to stick with the draft creation then publish with the ?send_email_when_published query.

When is this part of the API expected to stabilize?

No concrete timeline at the moment as the members and bulk email functionality is moving from the early prototype/beta to first-class feature. Sometime in the new year I expect.

No worries, the important thing is there is a way. (I hope the API won’t break too often…)