Eloqua BulkAPI 2.0 returns 404: There was a validation error

1.1k Views Asked by At

I am trying to create a contacts export in Eloqua following this tutorial.

The outcome I experience is:

HTTP/1.1 400 There was a validation error.
{
    "failures": [{
        "field": "name",
        "constraint": "Must be a string value, at least 1 character and at most 100 characters long."
    },
    {
        "field": "fields",
        "constraint": "Is required."
    }]
}

and makes no sense.

My requests are as follows:

POST https://<HOST>.eloqua.com/API/Bulk/2.0/contacts/exports

Request Body:

{
    "name": "Sample Contacts Export",
    "fields": {
        "UniqueId": "{{Contact.Id}}",
        "Subject": "{{Contact.Id}}",
        "FirstName": "{{Contact.Field(C_FirstName)}}",
        "LastName": "{{Contact.Field(C_LastName)}}",
        "Email": "{{Contact.Field(C_EmailAddress)}}",
        "Company": "{{Contact.Field(C_Company)}}",
        "JobTitle": "{{Contact.Field(C_Title)}}",
        "Address": "{{Contact.Field(C_Address1)}}",
        "City": "{{Contact.Field(C_City)}}",
        "Country": "{{Contact.Field(C_Country)}}",
        "Province": "{{Contact.Field(C_State_Prov)}}",
        "PostalCode": "{{Contact.Field(C_Zip_Postal)}}",
        "Phone": "{{Contact.Field(C_BusPhone)}}",
        "MobilePhone": "{{Contact.Field(C_MobilePhone)}}"
    }
}

and

POST https://<HOST>.eloqua.com/API/Bulk/2.0/contacts/exports

Request Body:

{
    "name":"Contact email export",
    "fields":{
        "EmailAddress":"{{Contact.Field(C_EmailAddress)}}"
    }
}

The latter is actually the example from the tutorial.

Do you have any idea what's wrong?

Thanks in advance.

3

There are 3 best solutions below

0
On

Your client might be including extra escape characters. Your definition is correct. Use a JSON formatter to validate the request body and copy+paste it to a program like fiddler and try it from there. I copy pasted the definition you posted and it works for me.

0
On

Thanks for getting back to me. Actually, the cause for the error is that the Accept header was missing. In order to successfully execute the request, it should include one of the following:

Accept: application/json

or

Accept: text/csv

0
On

Please, make sure you are adding the following header to the post request:

Content-Type application/json

I can reproduce your error if the header is omitted.

Request WITHOUT content-type

POST /API/Bulk/2.0/contacts/exports HTTP/1.1
Authorization: Basic *****

Body:
{
    "name":"Contact email export",
    "fields":{
        "EmailAddress":"{{Contact.Field(C_EmailAddress)}}"
    }
}

Response WITHOUT content-type

{
  "failures": [
    {
      "field": "name",
      "constraint": "Must be a string value, at least 1 character and at most 100 characters long."
    },
    {
      "field": "fields",
      "constraint": "Is required."
    }
  ],...
}

Request with content-type

POST /API/Bulk/2.0/contacts/exports HTTP/1.1
Authorization: Basic *****
Content-Type: application/json

Body:
{
    "name":"Contact email export",
    "fields":{
        "EmailAddress":"{{Contact.Field(C_EmailAddress)}}"
    }
}

Response with content-type

{
  "name": "Contact email export",
  "fields": {
    "EmailAddress": "{{Contact.Field(C_EmailAddress)}}"
  },
  "dataRetentionDuration": "PT12H",
  "uri": "/contacts/exports/2",
  "createdBy": "*****",
  "createdAt": "2016-03-09T14:33:03.0520813Z",
  "updatedBy": "*****",
  "updatedAt": "2016-03-09T14:33:03.0520813Z"
}