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

Problem with content parameter on SendGridEmail #43

Open
siciliano2281 opened this issue Mar 3, 2022 · 1 comment
Open

Problem with content parameter on SendGridEmail #43

siciliano2281 opened this issue Mar 3, 2022 · 1 comment

Comments

@siciliano2281
Copy link

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!

@melgu
Copy link
Contributor

melgu commented Nov 15, 2022

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.

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

No branches or pull requests

2 participants