Trying to upload a file

Highlighted
Occasional Advisor

Trying to upload a file

I get the URL by creating a list and then passing it in the lists field.


I keep getting (415) Unsupported Media Type


Here is what I am using:


request.ContentType = "multipart/form-data"

activityType=ADD_CONTACTS


&dataFile=Y%3a%5cConstantContact%5cEmailList.csv


&lists=https%3a%2f%2fapi.constantcontact.com%2fws%2fcustomers%2fNightingalenurses%2flists%2f18


12 REPLIES 12
Highlighted
Occasional Advisor

I realized I was posting to

I realized I was posting to the list URI instead of the activities one


Now I am posting to


https://api.constantcontact.com/ws/customers/Username/activities


And I am getting a 400 Bad request error.


 


I also tried adding fileType = CSV and changing dataFile to FileName, I don't reallly know what the difference between those are.

Highlighted
Moderator

When using

When using multipart/form-data, you must send the contents of the csv file as the value for data file, not the name of the file.  This varies on how you do this depending on the language, typically you just need to read the file to your request stream on most languages.  PHP is slightly different and we can get a sample of how to do this if you need one.


 


It's worth mentioning, we are in the process of updating the sample code packs to include code for doing these types of imports as well.  Will update everyone once the new samples are done.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Advisor

Ok is there any limit to the

Ok is there any limit to the amount of data that can be passed in this manner? Could I upload thousands of emails by just building out one long string of data?

Highlighted
CTCT Employee

Max number of contacts posted at once

Hi,



The limit to uploading a number of contacts using our Activities Collection, as well as in our User Interface, is 20,000 contacts at a time.



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Highlighted
Occasional Advisor

It is confusing that you

It is confusing that you mention file types. I can have whatever file type I want since I must read it in myself and convert it to a string. IT doesn't make sense to say you can have txt or csv file. I must read whatever file I have into memory and then send it, or am I missing something?

Highlighted
Occasional Advisor

I tried this data

activityType=SV_ADD&data=test4%40test.com%0atest4%40test.com%0atest4%40test.com%0atest4%40test.com%0a&lists=http%3a%2f%2fapi.constantcontact.com%2fws%2fcustomers%2fNightingalenurses%2flists%2f31


I am getting a 400 Bad Request response. Any ideas of what could be causing the problem?

Highlighted
CTCT Employee

This string looks to be

This string looks to be formatted correctly, and I was able to use it to create contacts in my account without an issue. The one thing that did cause a 400 error at first was the fact that I do not have a list with the id of '31'. Once I modified this to a list id in my account (ie: 1), this string worked properly. I would check to insure you do have a list with the id of 31. You can determine which list id's belong with which list by performing an http get on the lists collection, which you can find more information on here. I would also check to insure that there are no unintended whitespace or linebreak characters included in your request body.


 


Regarding your earlier comment on us the documentation for this bulk upload saying you can have a text or csv file, this is meant as more of a deterrent from people using an excel file with this method, which should be uploaded using a multipart/from-data request, but I certainly apologize for any confusion that this has caused.


 


Please let me know if you have any other questions or are still experiencing difficulties getting this action to work and I will be happy to help.


 

David J

Highlighted
Occasional Advisor

I am creating the list in the

I am creating the list in the same program. I am using the URI passed back to me from that. I checked and verified that the list I just created is on my account when I log in. Is there a delay from when the list is created until it will be recognized in the API?


I also tried changing it to list 1 but that doesn't help either, I get the same 400 bad request.


activityType=SV_ADD&data=test4%40test.com%0atest4%40test.com%0atest4%40test.com%0atest4%40test.com%0a&lists=http%3a%2f%2fapi.constantcontact.com%2fws%2fcustomers%2fNightingalenurses%2flists%2f1

 

Highlighted
CTCT Employee

Re: I am creating the list in the

I am using RESTClient, which you can find more information about at - http://developer.constantcontact.com/doc/restclient. This allows you to test GET PUT POST and DELETE http requests, and returns the response from the server. This is very beneficial for testing your API calls by alleviating any issues that may be caused by the program language you are using, and also allows you to test the response from the server without actually having to modify your program. Using this, I have simply copy and pasted your request without making any modifications, and it successfully created an activity in my account.


With that being said, it seems likely the issue lies outside of the actual string that you are posting to the activities collection. If you would like to send the full program you are using over to our webservices support team, I would be happy to review it and hopefully provide some additional feedback. Please let me know if you have any other questions. Thank you.

David J

Developer Portal

View API documentation, code samples, get your API key.

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured