[英]How to pass values to a list in ActiveCampaign using C#
我在ActiveCampaign(電子郵件營銷API)中有一個列表。 在這里,我需要添加具有3個參數firstName,lastName,email的聯系人。 這些參數應使用C#控制台應用程序傳遞到該列表。 因此,首先我需要使用其API密鑰訪問ActiveCampaign API。 並且還有該特定列表的列表ID。 然后,我需要使用C#控制台應用程序將值傳遞到該列表。 這是我的示例代碼。 請幫我實現它
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace ActiveCampaignListAdd
{
class Program
{
private const string URL = "https://osandadeshannimalarathna.api-us1.com";
private string API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static string api_action = "/admin/api.php?api_action=contact_add";
private static string listIDAndStatus = "?listid=2&status=1";
// private string api_output = "Json";
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(URL);
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// List data response.
HttpResponseMessage response = client.GetAsync(api_action + listIDAndStatus).Result; // Blocking call!
if (response.IsSuccessStatusCode)
{
// Parse the response body. Blocking!
var dataObjects = response.Content.ReadAsAsync<IEnumerable<Contacts>>().Result;
foreach (var d in dataObjects)
{
Console.WriteLine(d.firstName);
Console.WriteLine(d.lastName);
Console.WriteLine(d.email);
}
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
}
}
public class Contacts
{
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
}
}
有幾個免費的Activecampaign C#庫。 我將從選擇一個開始...只需搜索GitHub。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.