Please help :( I tried to do this exactly like the API documentation.... Is there anything im missing or not adding. I of course get the 400 error.
Thanks
privatevoid btn_ContactEmailSubmit_Click(object sender, EventArgs e)
{
if (txtbox_ContactEmail != null)
{
string NewListName = txtbox_ContactEmail.Text;
string Resource = API_RESOURCE_CONTACTS;
string Url = String.Format("https://api.constantcontact.com/ws/customers/{0}/{1}", API_USERNAME, Resource);
CredentialCache CredentialCache = newCredentialCache();
CredentialCache.Add(
newUri(Url), "Basic", newNetworkCredential(API_KEY + "%" + API_USERNAME, API_PASSWORD));
try
{
XDocument NewContact = newXDocument
(
newXDeclaration("1.0", "utf-8", "no"),
newXElement
(
Atom + "entry",
newXAttribute("xmlns", "http://www.w3.org/2005/Atom"),
newXElement(Atom + "title=\"text\"", "" ),
newXElement(Atom + "updated", "2011-09-02"),
newXElement(Atom + "author", ""),
newXElement(Atom + "id", "data:,none"),
newXElement(Atom + "summary",
newXAttribute("type=\"text\"", "Contact")),
newXElement(Atom + "content",
newXAttribute("type", "application/vnd.ctct+xml"),
newXElement(ConstantContact + "Contact",
newXAttribute("xmlns", "http://ws.constantcontact.com/ns/1.0/"),
newXElement(ConstantContact + "EmailAddress", txtbox_ContactEmail.Text),
newXElement(ConstantContact + "OptInSource", "ACTION_BY_CUSTOMER"),
newXElement(ConstantContact + "ContactLists",
newXElement(ConstantContact + "ContactList", newXAttribute("id", "https://api.constantcontact.com/ws/customers/{myusername}/lists/1"))
)
)
)
)
);
string Response = NewContact.Post(Url, CredentialCache);
MessageBox.Show("You have successfully created a new Contact!");
txtbox_ContactEmail.Clear();
}
catch
{
MessageBox.Show("An Error has occured!");
}
}
}
Solved! Go to Solution.
?? I really dont know what I can do on my end for this problem.
Hey,
Did you make sure that your choosing the Id of the contact and passing it to that URI. Let me know the email address and the ID so i can test it on my side.
CredentialCache LoginCredentials = newCredentialCache();
string ContactURI = String.Format("https://api.constantcontact.com/ws/customers/{0}/{1}/5608", API_USERNAME, API_RESOURCE_CONTACTS);
LoginCredentials.Add(
newUri(@"https://api.constantcontact.com/ws/customers/smimarketing"), "Basic", newNetworkCredential(API_KEY + @"%" + API_USERNAME, API_PASSWORD));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ContactURI);
request.Credentials = LoginCredentials;
request.Method =
"PUT";
request.ContentType =
@"application/atom+xml";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string returnString = response.StatusCode.ToString();
Console.WriteLine(returnString);
MessageBox.Show("You have successfully updated a Contact!");
Email: hello@hello.com
ID: 5608
List: 28
the current list it is in is 1
What error is it returning with?
409 conflict
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
????
?? I really dont know what I can do on my end for this problem.
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article