What is the correct date format for API requests?

  • 1
  • 2
  • Question
  • Updated 1 year ago
  • Answered
Hi,

We are using the MyEmma API to bulk import members, as this is described as the preferred way in the documentation.  I have added several custom fields to our members, 2 of which are Date fields.  The JSON posted to the bulk import looks something like this...

{
"members": [
{ "email": "fred@bloggs.com", "fields": { "full_name": "Fredrick Bloggs", "custom_date_field": "@D:2015-05-20T12:34:56" } }
]
}
When I post this JSON to the bulk import API endpoint, I get a HTTP status 200 (OK) result and an ImportID in the HTTP body.  But, when using the API endpoint to check the status of the import, I always have a "Import failed" error, with no other explanation.

However, if I send the exact same request, but, remove the custom_date_field, the import completes successfully every time.

I have also tried the following date formats with the corresponding results:

- "2015-05-20T12:34:56"     "Import failed, invalid date 2015-05-20T12:34:56"
- "2015-05-20"                     "Import failed, invalid date 2015-05-20"
- "@D:2015-05-20"              "500 Internal Server Error"

I cant find any documentation on how dates for custom fields should be formatted when making API requests.

Can anyone shed any light on this please?

Many Thanks
Photo of Rejuvenine

Rejuvenine

  • 4 Posts
  • 0 Reply Likes
  • frustrated

Posted 3 years ago

  • 1
  • 2
Photo of Katie Lewis

Katie Lewis, Official Rep

  • 3414 Posts
  • 309 Reply Likes
Hi! It looks like you don't have a date field with that name, which may be the problem, or maybe your code above is just an example?

The proper date format is:
"date-picker": "@D:1982-12-10"

So you might have something like this:

{
"fields": {
"first_name": "Sally",
"last_name": "Forth",
"initial_order_date": "@D:2015-12-10"
},
"email": "sallyforth@company.com"
}

I hope this helps!
Photo of Rejuvenine

Rejuvenine

  • 4 Posts
  • 0 Reply Likes
Hi Katie,

I was just using custom_date_field as an example.  The 2 fields we are using are signup_date and initial_order_date.  When specifying any date in either or both of these fields I always get a "Import failed" error.  Whats even more strange, if I use the format from your example "@D:2015-12-10" (omit the time portion) the API returns "500 Internal Server Error".  Only when both date fields are null it succeeds.

Can you confirm your example works correctly?

Failing that, I can send you the full HTTP packet if there is a private way to do this?

Many Thanks
Photo of Rejuvenine

Rejuvenine

  • 4 Posts
  • 0 Reply Likes
Hi again,

Heres a copy of the HTTP request/response using the example from your reply (Note: I have xxx'd out the account ID and the auth header for security)..

Request:
POST https://api.e2ma.net/xxxxxx/members HTTP/1.1
User-Agent: Fiddler
Authorization: Basic xxxxxx
Content-Type: application/json
Host: api.e2ma.net
Content-Length: 241

{    "members": [
        {
             "email":"testing@test.com",
             "fields": {
                 "full_name": "Mr Testy Tester",
                 "initial_order_date": "@D:2015-12-10"
             }
        }
    ]
}
Response:
HTTP/1.1 500 Internal Server Error
Date: Thu, 21 May 2015 07:18:39 GMT
Server: Apache/2.2.22 (Ubuntu)
x-varnish: 1210803082
accept-ranges: bytes
connection: keep-alive, close
via: 1.1 varnish
age: 0
Content-Length: 65
Content-Type: application/json
{"error": "datetime.date(2015, 12, 10) is not JSON serializable"}

Notice with the date format from your reply I get a 500 Internal server error.  However, if I now append a time, the request and response are as follows:

Request:
POST https://api.e2ma.net/xxxxxx/members HTTP/1.1
User-Agent: Fiddler
Authorization: Basic xxxxxx
Content-Type: application/json
Host: api.e2ma.net
Content-Length: 250

{    "members": [
        {
             "email":"testing@test.com",
             "fields": {
                 "full_name": "Mr Testy Tester",
                 "initial_order_date": "@D:2015-12-10T12:34:56"
             }
        }
    ]
}
Response:
HTTP/1.1 200 OK
Date: Thu, 21 May 2015 07:42:30 GMT
Server: Apache/2.2.22 (Ubuntu)
x-varnish: 1210853992
accept-ranges: bytes
connection: keep-alive
via: 1.1 varnish
age: 0
Content-Length: 27
Content-Type: application/json; charset=utf8

{
  "import_id": 12726620
}
So, being a 200 result, the import was accepted.  Now I check the import ID with the following request/response:

Request:

GET https://api.e2ma.net/xxxxxxx/members/imports/12726620 HTTP/1.1
User-Agent: Fiddler
Authorization: Basic xxxxxxxx
Content-Type: application/json
Host: api.e2ma.net
Content-Length: 0

Response:
HTTP/1.1 200 OK
Date: Thu, 21 May 2015 07:46:34 GMT
Server: Apache/2.2.22 (Ubuntu)
x-varnish: 1210863191
accept-ranges: bytes
connection: keep-alive
via: 1.1 varnish
age: 0
Content-Length: 410
Content-Type: application/json; charset=utf8
{
  "import_id": 12726620, 
  "status": "e", 
  "style": "add_and_update", 
  "import_started": "@D:2015-05-21T02:42:30", 
  "account_id": xxxxxxx, 
  "error_message": "Import failed", 
  "num_members_updated": 0, 
  "source_filename": "", 
  "fields_updated": [], 
  "num_members_added": 0, 
  "import_finished": "@D:2015-05-21T02:42:32", 
  "groups_updated": [], 
  "num_skipped": 0, 
  "num_duplicates": 0
}

As you can see, the error message is "Import Failed" with no reason.

I wont do a request/response for a successful import because its simpler to say, if I omit all dates from the request, then the import succeeds every time.

Is this a bug in the MyEmma bulk importer, or am I doing something wrong?

Many Thanks
Photo of Rejuvenine

Rejuvenine

  • 4 Posts
  • 0 Reply Likes
Hello yet again!

So, after further testing, Im convinced this is a MyEmma bug in the Bulk Member Import API endpoint.  Reason being, if I use the API endpoint which creates a single member (i.e. not the bulk import endpoint) then the member is created successfully with the specified dates.  Heres the request/response....

Request:
POST https://api.e2ma.net/xxxxxx/members/add HTTP/1.1
User-Agent: Fiddler
Authorization: Basic xxxxxx
Content-Type: application/json
Host: api.e2ma.net
Content-Length: 144

{
"email":"testing@test.com",
"fields": {
"full_name": "Mr Testy Tester",
"initial_order_date": "@D:2015-12-10T12:34:56"
}
}

Response:

HTTP/1.1 200 OK
Date: Thu, 21 May 2015 08:14:37 GMT
Server: Apache/2.2.22 (Ubuntu)
x-varnish: 1210917022
accept-ranges: bytes
connection: keep-alive
via: 1.1 varnish
age: 0
Content-Length: 64
Content-Type: application/json; charset=utf8

{
  "status": "a", 
  "added": true, 
  "member_id": 851968348
}

And I can see the member in the MyEmma console.  So, I guess Ill modify my code to not use the bulk import endpoint and hit the single "add member" endpoint for each new user.
Photo of Katie Lewis

Katie Lewis, Official Rep

  • 3414 Posts
  • 309 Reply Likes
I think I may have just given you the wrong date format -- I went back to our developers, and now they're saying that you'll have success with MM/DD/YYYY.

They tried an API import (using the /members endpoint), with the following JSON:


{
"members": [
{
"email": "user+1@myemma.com",
"fields": {
"first_name": "User",
"last_name": "One",
"date": "05/22/2015" }
},
{
"email": "user+2@myemma.com",
"fields": {
"first_name": "User",
"last_name": "Two",
"date": "05/22/2015" }
},
{
"email": "user+3@myemma.com",
"fields": {
"first_name": "User",
"last_name": "Three",
"date": "05/22/2015"
}
},
{
"email": "user+4@myemma.com",
"fields": {
"first_name": "User",
"last_name": "Four",
"date": "05/22/2015"
}
},
{
"email": "user+5@myemma.com",
"fields": {
"first_name": "User",
"last_name": "Five",
"date": "05/22/2015"
}
},
{
"email": "user+6@myemma.com",
"fields": {
"first_name": "User",
"last_name": "Six",
"date": "05/22/2015"
}
},
{
"email": "user+7@myemma.com",
"fields": {
"first_name": "User",
"last_name": "Seven",
"date": "05/22/2015"
}
}
]

Does that seem to work for you?
Photo of 1040.com

1040.com

  • 2 Posts
  • 0 Reply Likes
We have this same issue. When we pass a timestamp with the bulk member api it fails with no reason. If you send exactly the same data to the single member add api, it works. It's important for our purposes to send a timestamp, not just a date.

I see this is two years old now. Any chance it will be fixed?
Photo of Grey Stepp

Grey Stepp, Support Team Manager

  • 1698 Posts
  • 135 Reply Likes
Hey there, 

Could you send along an example of your JSON so we can take a look?  We did some testing on our end and were able to successfully pass a bulk import with a date and timestamp, so we'd like to take a deeper look.  

I'll be watching out for your reply! 

- G
Photo of 1040.com

1040.com

  • 2 Posts
  • 0 Reply Likes
Thanks for looking into this. An example request is below:

POST https://api.e2ma.net/******/members HTTP/1.1
Authorization: Basic ************
Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
User-Agent: RestSharp/105.2.3.0
Content-Type: application/json
Host: api.e2ma.net
Content-Length: 977
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

{
  "members": [
    {
      "email": "t****i@gmail.com",
      "fields": {
        "IsFFA": "false",
        "IsFedAccepted": "false",
        "HoursSinceActive": "1406",
        "HasOptedOut": "false",
        "HasEfiledReturn": "false",
        "LastLoginDT": "@D:2017-02-05T21:39:31"
      }
    },
    {
      "email": "c****y@comcast.net",
      "fields": {
        "IsFFA": "false",
        "IsFedAccepted": "true",
        "HoursSinceActive": "1012",
        "HasOptedOut": "false",
        "HasEfiledReturn": "true",
        "LastLoginDT": "@D:2017-02-22T07:35:10"
      }
    },
    {
      "email": "w****k@icloud.com",
      "fields": {
        "IsFFA": "false",
        "IsFedAccepted": "false",
        "HoursSinceActive": "1357",
        "HasOptedOut": "false",
        "HasEfiledReturn": "false",
        "LastLoginDT": "@D:2017-02-07T22:38:22"
      }
    }
  ],
  "source_filename": null,
  "group_ids": []
}
Photo of Anthony Miranda

Anthony Miranda, Customer Support Specialist

  • 135 Posts
  • 16 Reply Likes
Thanks for passing that along! Taking a look at it, I'm not seeing anything jump out at me that would be causing issues. Can you share what HTTP response you get back when you make this call?

I also want to point out that our Date Picker fields don't recognize timestamps and they'll just ignore that data and update the date (XX/XX/XXXX). If it's absolutely necessary to bring in a timestamp, you're going to be more successful creating a new field that is a "short answer" type, as that will have no trouble bringing in date info with a timestamp.