hubspot-net / HubSpot.NET

C# .NET Wrapper around the common HubSpot APIs.
MIT License
112 stars 137 forks source link

Map date time properties #98

Closed jmawebtech closed 3 years ago

jmawebtech commented 3 years ago

Describe the bug

I bound a DateTime property to the total milliseconds of a time, but I receive this error:

HubSpot.NET.Core.HubSpotException: 'Error from HubSpot, JSONResponse={"validationResults":[{"isValid":false,"message":"1606768561954 is at 20:36:1.954 UTC, not midnight!","error":"INVALID_DATE","name":"trial_end_date"},{"

Repro Steps

Here is my code:

    /// <summary>
    /// Sync new contacts from Connex to HubSpot
    /// </summary>
    [TestMethod]
    public void Contact_IfNewContact_CreateContact()
    {
        long unixTimestamp = (long)DateTime.Now.ToUniversalTime().Subtract(
            new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
            ).TotalMilliseconds;

        provider.Contacts.CreateConnexContact(new ConnexContact()
        {
            Email = "john@squaredup.com",
            BillingUserName = "mybillingusername",
            ConnexForQuickBooksUserName = "connexusername",
            DateCreditCardFailed = unixTimestamp,
            InitialOrderId = "100",
            InitialPurchaseDate = unixTimestamp,
            QBVersion = "QuickBooks Desktop",
            SubscriptionTransactionId = "RP123",
            TrialExpirationDate = unixTimestamp,
            WhatElseShouldWeKnow = "Test",
            WhatSystemConnect = "Test",
            FirstName = "John",
            TrialExtended = "true",
            LastName = "Smith",
            Phone = "00000 000000",
            Company = "Squared Up Ltd."
        });
    }

Expected behavior

I expected a DateTime property to bind.

Screenshots If applicable, add screenshots to help explain your problem.

*Anything else?**

Can you add examples on how to map DateTime properties to your documentation?

jmawebtech commented 3 years ago

Here is the final code:

        long unixTimestamp = (long)DateTime.Today.TimeOfDay.TotalMilliseconds;

        provider.Contacts.CreateConnexContact(new ConnexContact()
        {
            Email = "john2@squaredup.com",
            BillingUserName = "mybillingusername",
            ConnexForQuickBooksUserName = "connexusername",
            DateCreditCardFailed = unixTimestamp,
            InitialOrderId = "100",
            InitialPurchaseDate = unixTimestamp,
            QBVersion = "QuickBooks Desktop",
            SubscriptionTransactionId = "RP123",
            TrialExpirationDate = unixTimestamp,
            WhatElseShouldWeKnow = "Test",
            WhatSystemConnect = "Test",
            FirstName = "John",
            TrialExtended = "true",
            LastName = "Smith",
            Phone = "00000 000000",
            Company = "Squared Up Ltd."
        });