Subscriber.AddAndResubscribeWithCustomFields
Adds a subscriber to a subscriber list, including adding custom field data for the subscriber.
If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the confirmation email you have set up for the list being subscribed to.
Please note:
- Since this method uses an array for the custom fields it can only be accessed via SOAP, and not HTTP-GET/POST.
- If the subscriber is in an inactive state or has previously been unsubscribed, they will be re-added to the active list. Therefore, this method should be used with caution and only where suitable.
Samples
The following samples include specific examples of this method in action. For the samples that have a subscribewithcustom example, changing the operation name from Subscriber.AddWithCustomFields to Subscriber.AddAndResubscribeWithCustomFields will get you calling this method instead.
- .NET - 51kb (see subscribewithcustom.aspx)
- PHP - 13kb (see subscribewithcustom.php)
- Classic ASP - 3kb (see subscribewithcustom.asp)
- Flash - 978kb (see customfieldsexample.fla)
- Perl - 1kb (see subscribewithcustom.txt)
- Cold Fusion - 2kb (see subscribewithcustom.cfm)
Parameters and required information
Here's a list of all the parameters you'll need to pass to the Subscriber.AddAndResubscribeWithCustomFields method. All of the parameters are required unless otherwise noted.
ApiKey- Your Campaign Monitor API Key. See here for more details.
ListID- The list you want to add the subscriber to. See here for more details.
Email- The email address of the new subscriber.
Name- The name of the new subscriber. If the name is unknown, an empty string can be passed in.
CustomFields- An array of custom fields for the subscriber. The custom fields are defined by key/value pairs. See here for more details.
Return Codes
Success
0: Success- The subscription was successful.
Error
1: Invalid email address- The email value passed in was a valid email address.
100: Invalid API Key- The API key passed was not valid or has expired.
101: Invalid ListID- The ListID value passed in was not valid.
SOAP 1.1
The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.
POST /api/api.asmx HTTP/1.1 Host: app.campaignmonitor.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://app.campaignmonitor.com/api/Subscriber.AddAndResubscribeWithCustomFields" <?xml version="1.0" encoding="utf-8"?> <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/"> <soap:Body> <Subscriber.AddAndResubscribeWithCustomFields xmlns="http://app.campaignmonitor.com/api/"> <ApiKey>string</ApiKey> <ListID>int</ListID> <Email>string</Email> <Name>string</Name> <CustomFields> <SubscriberCustomField> <Key>string</Key> <Value>string</Value> </SubscriberCustomField> <SubscriberCustomField> <Key>string</Key> <Value>string</Value> </SubscriberCustomField> </CustomFields> </Subscriber.AddAndResubscribeWithCustomFields> </soap:Body> </soap:Envelope>
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <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/"> <soap:Body> <Subscribers.AddAndResubscribeWithCustomFieldsResponse xmlns="http://app.campaignmonitor.com/api/"> <Subscribers.AddAndResubscribeWithCustomFieldsResult> <Code>int</Code> <Message>string</Message> </Subscribers.AddAndResubscribeWithCustomFieldsResult> </Subscribers.AddAndResubscribeWithCustomFieldsResponse> </soap:Body> </soap:Envelope>