【问题标题】:How to pass values to a list in ActiveCampaign using C#如何使用 C# 将值传递给 ActiveCampaign 中的列表
【发布时间】:2016-12-25 17:34:47
【问题描述】:

我在 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; }
}

}

【问题讨论】:

    标签: c# api rest httpclient


    【解决方案1】:

    有几个免费的 Activecampaign C# 库可用。我会先选择一个...只需搜索 GitHub。

    【讨论】:

      猜你喜欢
      • 2015-02-05
      • 2015-03-13
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 2017-08-12
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多