Link to home
Start Free TrialLog in
Avatar of HADDADD3
HADDADD3

asked on

Constant Contact API Error

Ive found the issue. My loop is incorrect, the last cycle of my loop is insert a %0A, how can i make it so that on the last leg of the loop %0A is not inserted?
Without looking at your encoded URL to see the exact issue I believe the problem is in your population loop:
 
While dr.Read()
If dr(1).ToString <> "" Then
data.Append(HttpUtility.UrlEncode((dr(0).ToString() & ", "), Encoding.UTF8))
data.Append(HttpUtility.UrlEncode(dr(1).ToString(), Encoding.UTF8))
data.Append(HttpUtility.UrlEncode(vbLf, Encoding.UTF8))
End If
End While
 
You put a %0A at the end of every entry up until the addition of the data.Append("&lists=") command. This results in an extra %0A before the &lists= in the encode URL. Notice this example of a working string and you should see what I'm talking about:
 
activityType=SV_ADD
&data=Email+Address%2CFirst+Name%2CLast+Name%0A
wstest3%40example.com%2C+Fred%2C+Test%0A
wstest4%40example.com%2C+Joan%2C+Test%0A
wstest5%40example.com%2C+Ann%2C+Test <--- Note there is no %0A here
&lists=http%3A%2F%2Fapi.constantcontact.com%2Fws%2Fcustomers%2Fjoesflowers%2Flists%2F2
&lists=http%3A%2F%2Fapi.constantcontact.com%2Fws%2Fcustomers%2Fjoesflowers%2Flists%2F5

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial