Pregunta

I am looking for a way to use Campaign Monitor's API in my ASP.NET/VB Web application. I have not used any API before, thus reading their documentation is very difficult to understand.

If anyone has used it and is able to provide some instructions I would appreciate it; or if someone has some general usage instructions (if applied on any APi), be my guest! :)

I know this is not the typical "I have a problem and this is my problem and here's my effort so far" but any help would be much appreciated.

¿Fue útil?

Solución 2

I use campaign monitor for populating subscriber lists.

There are two methods to post your subscribers to lists. I'm going to stick to the simplest one. Let's round up somethings you need first.

  1. You'll need an API key (which I am sure you have).

  2. You'll need to create a subscribers list and after you create this list you'll need the list ID. To get the ID (which is wierd).You'll need to click into your subscriber list. This look for this towards the top. Single opt-in list (change name/type) Note: You are not going to change the name or edit anything but you have to click in here to get the ID. On the third section you will see this: API Subscriber List ID. If you're using the API, you'll need this ID to access this list. 000x0000xx0x0xx00x00xx (just an example.)

  3. You'll need a form to capture Name and Email. You'll need your listid which you got in the previous point.

Then you'll need to code a communication object.

If you are doing a straight forward call you'll need the name, email, and listid.

ListID ="000x0000xx0x0xx00x00xx";
Email ="JoeM@somethingemail.com";
Name = "Joe Middle";

APIKey = yourAPIKey;
APIURL = "http://api.createsend.com/";


ApiCall = variables.APIURL;
ApiCall &= "api/api.asmx/Subscriber.Add?ApiKey=" & variables.APIKey;
ApiCall &= "&ListID=" & URLEncodedFormat(arguments.ListID);
ApiCall &= "&Email=" & URLEncodedFormat(arguments.Email); 
ApiCall &= "&Name=" & URLEncodedFormat(arguments.Name);

Once you have your url build you use whatever method .net uses to post http.

Then you'll want to code for success or fail and do something with that info. post to http and call the result. apiResult.

apiResult = xmlParse(apiResult.fileContent);
try {intCount = ArrayLen(apiResult.Result.XMLChildren);}
catch(Any e){intCount = 0;}
if (intCount gt 0){apiResult = apiResult.Result.xmlChildren;}
// Error handling
if ( apiResult[1].xmlName eq "Code" and apiResult[2].xmlName eq "Message" ){
returnStruct['blnSuccess'] = 0;
returnStruct['errorCode'] = apiResult[1].xmlText;
returnStruct['errorMessage'] = apiResult[2].xmlText;
}
// Success
else {
// Return str
returnStruct['blnSuccess'] = 1;
returnStruct['returnString'] = apiResult.Result.xmlText;
}    

The code above was adapted from coldfusion and I didn't build it but it is cfscript which is not CFML and you can kind of interpret what is happening.

If you adapt this to .NET then all you are missing is your HTTP call stuff method.

To check log into Campaign Monitor and click on your list. You should see additions showing up, if not it is either you API key (not usually the case), your listID (could be the case), your code (most likely culprit).

This was hammered out in a hurry so apologies if the flow is weird.

Good luck!

Otros consejos

You can also use the Campaign Monitor API client library which is available on Nuget:

AuthenticationDetails auth = new ApiKeyAuthenticationDetails(apiKey);

var fields = new List<SubscriberCustomField>() {
    new SubscriberCustomField() { Key = "MyCustomField", Value = myVal }
};

var subscriber = new Subscriber(auth, listId);

subscriber.Add(email, fullName, fields, false);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top