Cannot get api to work using same code that is working elsewhere

Hi All,

Here is my code, this same code works on two other sites on the same server, except i have a different apikey ofcourse and different custom fields, otherwise it is exactly the same.


'--------- send to campaign monitor ----------------------

    postdata = "<?xml version=""1.0"" encoding=""utf-8""?>"
    postdata = postdata & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
    postdata = postdata & "<soap:Body>"
    postdata = postdata & "    <Subscriber.AddWithCustomFields xmlns=""http://app.campaignmonitor.com/api/"">"
    postdata = postdata & "        <ApiKey>aaaa</ApiKey>"
    postdata = postdata & "        <ListID>bbbbb</ListID>"
    postdata = postdata & "        <Email>" & cstr(email) & "</Email>"
    postdata = postdata & "        <Name>" & cstr(fname) & "</Name>"
    postdata = postdata & "        <CustomFields>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>id</Key>"
    postdata = postdata & "                  <Value>555</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>fname</Key>"
    postdata = postdata & "                  <Value>" & cstr(fname) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>lname</Key>"
    postdata = postdata & "                  <Value>" & cstr(lname) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>gender</Key>"
    postdata = postdata & "                  <Value>" & cstr(gender) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>dob</Key>"
    postdata = postdata & "                  <Value>" & cstr(dob) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>street</Key>"
    postdata = postdata & "                  <Value>" & cstr(street) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>phone</Key>"
    postdata = postdata & "                  <Value>" & cstr(phone) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>GNA</Key>"
    postdata = postdata & "                  <Value>gna</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
   
    postdata = postdata & "             <SubscriberCustomField>"
    postdata = postdata & "                  <Key>OptedOut</Key>"
    postdata = postdata & "                  <Value>" & cstr(gvstrOptedOut) & "</Value>"
    postdata = postdata & "             </SubscriberCustomField>"
                   
    postdata = postdata & "        </CustomFields>"
    postdata = postdata & "    </Subscriber.AddWithCustomFields>"
    postdata = postdata & "</soap:Body>"
    postdata = postdata & "</soap:Envelope>"
   
    Dim xmlhttp
    'Set xmlhttp=Server.CreateObject("Microsoft.XMLHTTP")
    'Set xmlhttp=Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    Set xmlhttp=Server.CreateObject("MSXML2.ServerXMLHTTP")
   
    xmlhttp.open "POST","http://app.campaignmonitor.com/api/api.asmx" ,false

    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhttp.setRequestHeader "SOAPAction", """http://app.campaignmonitor.com/api/Subscriber.AddWithCustomFields"""

    xmlhttp.send postdata
   
    xmlresponse = xmlhttp.responseText
   
    Response.Write xmlresponse
    REsponse.end
   
    'call Send("newsletter@charlies.co.nz", "tareq@fracture.co.nz", "campaign monitor test", xmlresponse)

' ----------------------------------------------------------


Here is the error i am getting -

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---&gt; System.InvalidOperationException: There is an error in XML document (1, 351). ---&gt; System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Xml.XmlConvert.ToInt32(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read14_SubscriberAddWithCustomFields()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>


i searched the forums and there is a similar issue here, but with no fix - http://www.campaignmonitor.com/forums/viewtopic.php?pid=3368#p3368

Any ideas?, thanks,

Fracture

fracture, 7 years ago

ummmm sorry all, nevermind, just as soon as i posted this i re-checked my listID and ApiKey and i had a mistake there.

Thanks anway :)

Mathew Mathew, 7 years ago

Glad you got that sorted out ;)


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor

Join 150,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098