/// <summary> /// Create a new campaign. /// </summary> /// <param name="accessToken">Constant Contact OAuth2 access token.</param> /// <param name="apiKey">The API key for the application</param> /// <param name="campaign">Campign to be created</param> /// <returns>Returns a campaign.</returns> public EmailCampaign AddCampaign(string accessToken, string apiKey, EmailCampaign campaign) { EmailCampaign emailcampaign = null; string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Campaigns); string json = campaign.ToJSON(); CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json); if (response.HasData) { emailcampaign = response.Get<EmailCampaign>(); } else if (response.IsError) { throw new CtctException(response.GetErrorMessage()); } return emailcampaign; }
/// <summary> /// Update a specific email campaign. /// </summary> /// <param name="campaign">Campaign to be updated.</param> /// <returns>Returns a campaign.</returns> public EmailCampaign UpdateCampaign(EmailCampaign campaign) { if (campaign == null) { throw new IllegalArgumentException(CTCT.Resources.Errors.EmailCampaignOrId); } string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Campaign, campaign.Id)); // Invalidate data that are not supported by the update API procedure campaign.CreatedDate = null; campaign.TrackingSummary = null; campaign.ModifiedDate = null; campaign.IsVisibleInUI = null; // Convert to JSON string string json = campaign.ToJSON(); RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json); try { var emailCampaign = response.Get<EmailCampaign>(); return emailCampaign; } catch (Exception ex) { throw new CtctException(ex.Message, ex); } }
/// <summary> /// Update a specific email campaign. /// </summary> /// <param name="accessToken">Constant Contact OAuth2 access token.</param> /// <param name="apiKey">The API key for the application</param> /// <param name="campaign">Campaign to be updated.</param> /// <returns>Returns a campaign.</returns> public EmailCampaign UpdateCampaign(string accessToken, string apiKey, EmailCampaign campaign) { EmailCampaign emailCampaign = null; string url = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Campaign, campaign.Id)); // Invalidate data that are not supported by the update API procedure campaign.CreatedDate = null; campaign.TrackingSummary = null; campaign.ModifiedDate = null; campaign.IsVisibleInUI = null; // Convert to JSON string string json = campaign.ToJSON(); CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json); if (response.IsError) { throw new CtctException(response.GetErrorMessage()); } if (response.HasData) { emailCampaign = response.Get<EmailCampaign>(); } return emailCampaign; }
/// <summary> /// Create a new campaign. /// </summary> /// <param name="campaign">Campign to be created</param> /// <returns>Returns a campaign.</returns> public EmailCampaign AddCampaign(EmailCampaign campaign) { if (campaign == null) { throw new IllegalArgumentException(CTCT.Resources.Errors.EmailCampaignOrId); } string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.Campaigns); string json = campaign.ToJSON(); RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json); try { var emailcampaign = response.Get<EmailCampaign>(); return emailcampaign; } catch (Exception ex) { throw new CtctException(ex.Message, ex); } }