sendgrid icon indicating copy to clipboard operation
sendgrid copied to clipboard

Problem with content parameter on SendGridEmail

Open siciliano2281 opened this issue 4 years ago • 1 comments

Hi all! This library is phenomenal, thank you!

I'm running into a problem with the content parameter on the SendGridEmail object. Below is a snippet of my code:

`

    let resetCode = ["Reset_Code" : "945783"]
    email.content = [resetCode]
    
    let sendGridClient = req.application.sendgrid.client
    
    do {
        return try sendGridClient.send(emails: [email], on: req.eventLoop).transform(to: HTTPStatus.ok)
    } catch {
        req.logger.error("\(error)")
        return req.eventLoop.makeFailedFuture(error)
    }

`

I'm getting the following degugger message:

[ WARNING ] SendGridError(errors: Optional([SendGridKit.SendGridErrorResponse(message: Optional("The content type must be a string at least one character in length."), field: Optional("content.0.type"), help: Optional("http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content.type")), SendGridKit.SendGridErrorResponse(message: Optional("The content value must be a string at least one character in length."), field: Optional("content.0.value"), help: Optional("http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content.value"))])) [request-id: 421CDF29-DF11-40B9-81EA-A990C12C8267]

Clearly, the key "Reset_Code" and value "945783" are strings that are at least one character in length.

Any and all help is appreciated, thanks ahead of time!

siciliano2281 avatar Mar 03 '22 01:03 siciliano2281

I have a similar issue. Some documentation on how the content parameter should be structured would be nice.

I understood it to be Type: Value, so for example: ["text/plain": "Some text"], but that also doesn't work. Some guidance would be appreciated.

The SendGrid API itself accepts an array of JSON-Objects, like so:

[{ "type": "text/plain", "value": "some text" }]

SendGridKit 2.0.0 also works that way. So the best solution might be to just switch to the latest version of SendGridKit.

melgu avatar Nov 15 '22 12:11 melgu