简体   繁体   中英

SendGrid v3 Api dynamic template_id not recognised, won't send

I am trying to send a simple password reset email that's defined in a dynamic template. I have tested the template within SendGrid and it works fine. I have copied and pasted the template_id from the website, checked and double-checked it, but trying to post this message:

{
    "personalizations": [
        {
            "to": [
                {
                    "email": "chairman@##########.org.uk"
                }
            ],
            "dynamic_template_data": {
                "firstname": "Tim",
                "url": "https://localhost:5001/account/ProcessPasswordReset?id=4&code=############"
            },
            "send_at": 0
        }
    ],
    "from": {
        "email": "membership@##########.org.uk",
        "name": "A Person"
    },
    "reply_to_list": [],
    "subject": "Password Reset",
    "content": [],
    "template_id": "d-23a2c68a9e5349488be23299a04a9485",
    "send_at": 0
}

I get the following response

{
    "errors": [
        {
            "message": "Unless a valid template_id is provided, the content parameter is required. There must be at least one defined content block. We typically suggest both text/plain and text/html blocks are included, but only one block is required.",
            "field": "content",
            "help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content"
        }
    ]
}

As far as I can tell from the documentation, this is a well-formed message with a correct template_id.

Ok so the problem was the empty

"content": [],

This must not be sent at all if there is no content to send. Working as expected now this is removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM