Skip to content

MessageResource.CreateAsync throws formatting exception when supplying C# DateTime to sendAt parameter #596

@zornwal

Description

@zornwal

Issue Summary

Creating a message resource with the sendAt parameter set yields error response from Twilio API, stating invalid format, since wrong separators are used, . (dot) instead of : (colon)

Steps to Reproduce

  1. Create message with MessageResource.CreateAsync that has sendAt DateTime
  2. Receive exception response from API

Code Snippet

  public async Task SendSmsAsync(SmsMessage msg)
        {
            var conf = await _configurationProvider.GetConfiguration();

            await MessageResource.CreateAsync(@from: conf.From,
                to: msg.To,
                sendAt: msg.SendAt,
                scheduleType: MessageResource.ScheduleTypeEnum.Fixed,
                body: msg.Body,
                client: _twilioRestClientFactory.Create(conf));
        }

Exception/Log

API response:

{"code": 20001, "message": "Invalid SendAt: 2022-01-28T14.44.47Z. SendAt must be a valid ISO 8601 formatted datetime string: yyyy-MM-dd'T'HH:mm:ss'Z'", "more_info": "https://www.twilio.com/docs/errors/20001", "status": 400}

Exception trace (truncated):

Twilio.Exceptions.ApiException: Invalid SendAt: 2022-01-28T14.44.47Z. SendAt must be a valid ISO 8601 formatted datetime string: yyyy-MM-dd'T'HH:mm:ss'Z'
at Twilio.Clients.TwilioRestClient.ProcessResponse(Response response)
at Twilio.Clients.TwilioRestClient.RequestAsync(Request request)
at Twilio.Rest.Api.V2010.Account.MessageResource.CreateAsync(CreateMessageOptions options, ITwilioRestClient client)
at Twilio.Rest.Api.V2010.Account.MessageResource.CreateAsync(PhoneNumber to, String pathAccountSid, PhoneNumber from, String messagingServiceSid, String body, List`1 mediaUrl, Uri statusCallback, String applicationSid, Nullable`1 maxPrice, Nullable`1 provideFeedback, Nullable`1 attempt, Nullable`1 validityPeriod, Nullable`1 forceDelivery, ContentRetentionEnum contentRetention, AddressRetentionEnum addressRetention, Nullable`1 smartEncoded, List`1 persistentAction, ScheduleTypeEnum scheduleType, Nullable`1 sendAt, Nullable`1 sendAsMms, ITwilioRestClient client) [...]

Technical details:

  • twilio-csharp version: 5.70
  • csharp version: net6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions