trycourier / courier-python

A Python Package for communicating with the Courier REST API.
https://pypi.org/project/trycourier/
MIT License
29 stars 14 forks source link

Unable to create SendStep properly in ad hoc automation #84

Open arielo-galliot opened 3 months ago

arielo-galliot commented 3 months ago

Tried to create ad hoc automation with delay and send steps, but not sure how can I pass to in send step to point email of recipient. I noticed in the code that this step can receive profile - is this the way to pass recipient email? This is the code I am using:

import courier
from courier.client import Courier

...

response = client.automations.invoke_ad_hoc_automation(
            request = courier.AutomationAdHocInvokeParams(
                data = {
                    'email': data['email'],
                    'cancelation_token': cancelation_token
                },
                automation = courier.Automation(
                    cancelation_token=cancelation_token,
                    steps=[
                      courier.AutomationDelayStep(
                          action="delay",
                          duration="48 hours"
                      ),
                      courier.AutomationSendStep(
                          profile={"email": data["email"]},
                          template=template,
                          action="send",
                          data=data['template_data']
                      )
                  ]
                )
            )
        )

Running it receive this error:

status_code: 400, body: {'message': 'Invalid Steps Definition: one or more steps are incorrectly defined.', 'type': 'invalid_request_error'}, {'status_code': 400, 'body': {'message': 'Invalid Steps Definition: one or more steps are incorrectly defined.', 'type': 'invalid_request_error'}}
bwebs commented 3 months ago

It looks like recipient is the required missing field here

  courier.AutomationSendStep(
      profile={"email": data["email"]},
      template=template,
      action="send",
      data=data['template_data'],
      recipient=data["user_id"]
  )

We will update the AutomationSendStep spec then close the ticket.

It's worth noting that we have an AutomationV2SendStep which is preferred and has more options. recipient isn't required there