Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using cc or bcc with recipients substitution_data #118

Closed
medmunds opened this issue Jun 23, 2016 · 2 comments
Closed

Error using cc or bcc with recipients substitution_data #118

medmunds opened this issue Jun 23, 2016 · 2 comments
Assignees

Comments

@medmunds
Copy link

medmunds commented Jun 23, 2016

At some point in the past couple of weeks, SparkPost started rejecting the cc recipient in the following call:

from sparkpost import SparkPost
sp = SparkPost()
result = sp.transmissions.send(
    from_email='[email protected]',  # use a valid sender for your account
    recipients=[{
        'address': {'email': '[email protected]'},
        'substitution_data': {'order_no': '12345'}
    }],
    cc=['[email protected]'],
    subject='test',
    text='test merge {{ order_no }}'
)
# {'total_rejected_recipients': 1, 'total_accepted_recipients': 1, 'id': '102374996990914834', 'rcpt_to_errors': [{'message': 'invalid data format/type', 'code': '1300', 'description': 'field \'recipients[1].address.header_to\' value \'{ "substitution_data": { "order_no": "12345" }, "address": { "email": "[email protected]" } }\' is of type \'json_object\', but needs to be of type \'string\''}]}

The problem seems to be in the payload's header_to generated for the cc. If you omit the cc parameter, it works fine. Similarly, if you change to a simple recipients=['[email protected]'], the send is accepted (albeit without the intended substitution data).

This worked (or at least was accepted by the API) on 2016-06-07. I don't believe python-sparkpost has changed during that period. Is this a problem in python-sparkpost, or an intentional API clarification/change? If the latter, is there way to specify substitution_data and cc (or bcc) in the same transmission?

python 3.5 (or 2.7); python-sparkpost 1.2.0

medmunds referenced this issue in anymail/django-anymail Jun 23, 2016
python-sparkpost generates a transmissions.send
payload which is now considered invalid by the API,
if you try to use both `cc` (or `bcc`) and the
`recipients` dict structure required for merge_data.

[Anymail had been generating that recipients dict
structure in all cases, for simplicity. Sometime
between 2016-06-07 and 2016-06-22, SparkPost
began rejecting that if it appeared in the `header_to`
constructed by python-sparkpost.]
@richleland richleland self-assigned this Nov 13, 2016
@richleland
Copy link
Contributor

Tested this and it's still an issue. Sample response:

{u'total_accepted_recipients': 1, u'id': u'102478604587741873', u'rcpt_to_errors': [{u'message': u'invalid data format/type', u'code': u'1300', u'description': u'field \'recipients[1].address.header_to\' value \'{ "substitution_data": { "order_no": "12345" }, "address": { "email": "rich.leland+issue118@sparkpos...\' is of type \'json_object\', but needs to be of type \'string\''}], u'total_rejected_recipients': 1}

Looking at that error a json object is being passed to header_to, instead of what is required, a string.

@richleland
Copy link
Contributor

richleland commented Nov 13, 2016

Some further investigation - the issue appears to be in the _format_copies method which results in a payload being sent to SparkPost that looks like this:

{
  "description": null,
  "recipients": [
    {
      "substitution_data": {
        "order_no": "12345"
      },
      "address": {
        "email": "[email protected]"
      }
    },
    {
      "address": {
        "header_to": {
          "substitution_data": {
            "order_no": "12345"
          },
          "address": {
            "email": "[email protected]"
          }
        },
        "email": "[email protected]"
      }
    }
  ],
  "campaign_id": null,
  "return_path": "[email protected]",
  "content": {
    "from": {
      "email": "[email protected]"
    },
    "attachments": [],
    "text": "test merge {{ order_no }}",
    "headers": {
      "CC": "[email protected]"
    },
    "html": null,
    "reply_to": null,
    "use_draft_template": false,
    "template_id": null,
    "subject": "test"
  },
  "substitution_data": null,
  "options": {
    "skip_suppression": null,
    "open_tracking": null,
    "start_time": null,
    "inline_css": null,
    "transactional": null,
    "sandbox": null,
    "click_tracking": null,
    "ip_pool": null
  },
  "metadata": null
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants