The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Problem (Conn close because of error End of file reached) with Bulk Activities API, Ruby

Highlighted
Regular Visitor

Problem (Conn close because of error End of file reached) with Bulk Activities API, Ruby

I am not having sucess uploading a simple list of emails to the addcontacts url.

 

No other fields other than email and newline, three rcords.

 

I used ruby's net-http with Nick Siegers multipart enhancements so I could capture the exact exchange (below).  The actual api_key I used was changed for posting, but otherwise this is my log, verbatim:

 

opening connection to api.constantcontact.com...
opened
<- "POST /v2/activities/addcontacts?api_key=6oi8ku893d84my8gsfnr7m66 HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Ruby\r\nContent-Type: multipart/form-data; boundary=-----------RubyMultipartPost\r\nContent-Length: 469\r\nAuthorization: Bearer <REMOVED FOR SECURITY>\r\nHost: api.constantcontact.com\r\n\r\n"
<- "-------------RubyMultipartPost\r\nContent-Disposition: form-data; name=\"lists\"\r\n\r\n1433771127\r\n-------------RubyMultipartPost\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ncc_upload.csv\r\n-------------RubyMultipartPost\r\nContent-Disposition: form-data; name=\"data\"; filename=\"cc_upload.csv\"\r\nContent-Length: 56\r\nContent-Type: text/csv\r\nContent-Transfer-Encoding: binary\r\n\r\none@example.com \ntwo@example.com \nthree@example.com \n\r\n-------------RubyMultipartPost--\r\n\r\n"
Conn close because of error End of file reached

CODE BELOW

 

require 'net/http/post/multipart'

url = URI.parse('https://api.constantcontact.com/v2/activities/addcontacts?api_key=6oi8ku893d84my8gsfnr7m66')
File.open("cc_upload.csv") do |csv|
  req = Net::HTTP::Post::Multipart.new("#{url.path}?#{url.query}",
    'lists' => [1433771127],
    'file_name' => 'cc_upload.csv',
    'data' => UploadIO.new(csv, "text/csv", "cc_upload.csv"))
  req.add_field('Authorization', 'Bearer <REMOVED FOR SECURITY>')
  http_obj = Net::HTTP.new(url.host, url.port)
  http_obj.set_debug_output $stdout
  http_obj.use_ssl = true
  res = http_obj.start do |http|
    http.request(req)
  end
  puts res.body
end

 

Any thoughts?

1 REPLY 1
Highlighted
Moderator

Re: Problem (Conn close because of error End of file reached) with Bulk Activities API, Ruby

I redacted your OAuth token from your post.  I would recommend revoking the token and generating a new one as anyone who copied that token down now has access to your account.  If you would like to do so, please email webservices@constantcontact.com with your information and we will revoke the token for you.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured