Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

sendAt Error #19

Closed
goalguy10 opened this issue Jan 14, 2020 · 2 comments
Closed

sendAt Error #19

goalguy10 opened this issue Jan 14, 2020 · 2 comments

Comments

@goalguy10
Copy link

goalguy10 commented Jan 14, 2020

I am getting the below error when trying to use sendAt:

APIResponse(errors: [SendGrid.Exception.APIMessage(message: "Invalid type. Expected: integer, given: number.", field: Optional("send_at"), help: Optional("http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.send_at"))], _httpResponse: Optional(<NSHTTPURLResponse: 0x283415c20> { URL: https://api.sendgrid.com/v3/mail/send } { Status Code: 400, Headers {
    "Access-Control-Allow-Headers" =     (
        "Authorization, Content-Type, On-behalf-of, x-sg-elas-acl"
    );
    "Access-Control-Allow-Methods" =     (
        POST
    );
    "Access-Control-Allow-Origin" =     (
        "https://sendgrid.api-docs.io"
    );
    "Access-Control-Max-Age" =     (
        600
    );
    Connection =     (
        "keep-alive"
    );
    "Content-Length" =     (
        184
    );
    "Content-Type" =     (
        "application/json"
    );
    Date =     (
        "Tue, 14 Jan 2020 20:43:30 GMT"
    );
    Server =     (
        nginx
    );
    "X-No-CORS-Reason" =     (
        "https://sendgrid.com/docs/Classroom/Basics/API/cors.html"
    );
} }))

The code I am using is as follows:

let personalization = Personalization(recipients: recipientEmail)
        let plainText = Content(contentType: .plainText, value: "Test Email")
        let htmlText = Content(contentType: .htmlText, value: "<h1>Test Email</h1>")
        let email = Email(personalizations: [personalization],
                          from: fromEmail,
                          content: [plainText, htmlText],
                          subject: "Test Email"
        )

        email.parameters!.sendAt = Date(timeIntervalSinceNow: 24 * 60 * 60)
        
        do {
            try Session.shared.send(request: email) { (result) in
                switch result {
                    case .success(let response):
                        print("Success: ", response.statusCode)
                    case .failure(let err):
                        print("Error: ", err)
                    }
            }
        } catch {
            print(error)
        }
@goalguy10
Copy link
Author

Anybody monitoring this??

@scottkawai
Copy link
Owner

Hey @goalguy10,

Looks like the date was being sent as a float instead of an integer. I updated the library to 2.2.1, which should resolve the issue.

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

No branches or pull requests

2 participants