cancel
Showing results for 
Search instead for 
Did you mean: 

C# http request to bulk upload contacts from a file

Occasional Participant

C# http request to bulk upload contacts from a file

I need to upload near 40,000 contacts from our database to your.  I understand that you cannot have a file over 20k records, so I have broken this up into two files.  but now that I have the files, I am struggling on getting the HTTP post request setup to send the files to you.  Can you give me a hand with this?

 

Thanks,

rg

4 REPLIES 4
Moderator

Re: C# http request to bulk upload contacts from a file

Hello,


Thank you for reaching out to the API Support team here at Constant Contact. I'd be happy to help with what I can. I have a few questions for you: 

  • Are you seeing an error response at all?
  • Are you having trouble with both files, or just one?
  • Are you using our C# API wrapper library, or creating a POST request directly to our endpoint?
  • Are you submitting as a multipart/form-data or as a raw JSON payload?

I also want to mention that you can now import up to 40,000 contacts in a single file, up to 4mb in size.

 

Sincerely,
David B.
API Support Engineer

Occasional Participant

Re: C# http request to bulk upload contacts from a file

David,

I had not gotten that far yet.  I was unsure how to the the post request using the file, so I changed it to a json object, but my serializer is running out of memory with 20K records...(string Jsonized = JsonConvert.SerializeObject(contacts);), so I am going to have to cut down on the record count to get it through this part to the http request.

 

my plan is to create a post request to your endpoint directly, and I have no affinity to using files or a json payload.  I was just wondering if you had an example of a post request with a file...

 

thanks,

rg

Occasional Participant

Re: C# http request to bulk upload contacts from a file

so I have gotten past the json hurdle for the time being and I am trying to send just one contact and am getting a:  The remote server returned an error: (400) Bad Request.

here is the json string:  "[{\"Custom_Fields\":[{\"name\":\"CustomField1\",\"value\":\"\"},{\"name\":\"CustomField2\",\"value\":\"\"},{\"name\":\"CustomField3\",\"value\":\"0\"},{\"name\":\"CustomField4\",\"value\":\"0\"},{\"name\":\"CustomField5\",\"value\":\"1\"}],\"Home_Phone\":\"\",\"Work_Phone\":\"\",\"Cell_Phone\":\"\",\"First_Name\":\"Botana\",\"Last_Name\":null,\"Lists\":[],\"Email_Addresses\":[{\"Opt_In_Source\":\"ACTION_BY_OWNER\",\"Email_Address\":\"zstuff@mac.com\"}],\"Addresses\":[{\"Address_type\":\"Personal\",\"City\":\"Los Angeles\",\"Country_Code\":\"US\",\"Id\":\"1\",\"Line1\":\"1188 S. Longwood Ave.\",\"Line2\":\"\",\"Postal_Code\":\"90019\",\"State\":\"CA\",\"State_Code\":\"CA\"}]}]"

 

 

Moderator

Re: C# http request to bulk upload contacts from a file

Hello,

 

It should be noted that this endpoint and method you are using is for sending an individual contact. If you are trying to send multiple contacts, the payload will be different. For the full documentation on our bulk endpoint, see https://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html

 

Assuming that the slashes are simply escaping the quotation marks in your JSON from C#, here's what I see:

  • There should be no parameter for activity_type=ADD_CONTACT. This was used for bulk imports with our old V1 API and is not used with this method in V2.
  • The access token not added as a parameter, but is used in an Authorization header as "Bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" to properly authorize.
  • The entire payload should be a single object and not an array.
  • Your field and property names should be all lowercase.
  • You cannot use null as values for any fields, you would simply use an empty string ("").
  • The opt_in_source on an email address is read only, and you set the source as a URL parameter.
  • The ID on an address is read only and is assigned by Constant Contact when it is created.
  • The address_type needs to be either "PERSONAL" or "BUSINESS", and must be all caps.
  • If you are setting a state_code, the state needs to match the name of that state. E.g. state_code of CA means the state field needs to be "California" -- if you are using the state_code field, you can omit the state field.

Here is an example of a call to that endpoint:

POST https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_OWNER&api_key=xxxxxxxx
Headers:
Content-Type : application/json
Authorization : Bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Body:
{
"addresses": [
{
"address_type": "PERSONAL",
"city": "Los Angeles",
"country_code": "US",
"line1": "1188 Anywhere Ave.",
"line2": "",
"postal_code": "12345",
"state_code": "CA"
}
],
"lists": [
{
"id": "1"
}
],
"cell_phone": "",
"email_addresses": [
{
"email_address": "xxxxx@xxxxx.com"
}
],
"home_phone": "",
"work_phone": "",
"first_name": "Joe",
"last_name": "Smith",
"custom_fields": [
{
"name": "CustomField3",
"value": "0"
}, {
"name": "CustomField4",
"value": "0"
}, {
"name": "CustomField5",
"value": "1"
}
]
}

 

Sincerely,
David B.
API Support Engineer