MailChimp MCAPI.NET - Subscription Groupings - c#

I'm interfacing with MailChimp using MCAPI.NET and I need to specify the groupings for subscriptions.
string emailAddr = "somebody#somewhere.net";
MailChimp.MCApi mc = new MailChimp.MCApi("myapikey", true);
var merges = new MailChimp.Types.List.Merges();
merges.Add("FNAME", "MyFirstName");
merges.Add("LNAME", "MyLastName");
var group = new string[]{"PSS"};
var grp = new MailChimp.Types.List.Grouping("Staff Type", group);
merges.Add("Groupings", grp);
mc.ListSubscribe("mylistid", emailAddr, merges);
My grouping isn't getting set. Does someone have a working example they could share?

The problem with your code is that you are not adding a list of groupings to the merge var "Groupings". The value has to be of the following type:
MailChimp.Types.MCList<MailChimp.Types.List.Grouping>
Here is a working copy:
var merges = new List.Merges();
var groupingList = new MailChimp.Types.MCList<MailChimp.Types.List.Grouping>();
var grouping = new MailChimp.Types.List.Grouping(myGroupId, new string[] { group1, group2 });
groupingList.Add(grouping);
merges["Groupings"] = groupingList;
// You may find it practical to include the following options, at least while testing the groupings
var options = new MailChimp.Types.List.SubscribeOptions();
options.DoubleOptIn = false;
options.ReplaceInterests = false;
options.SendWelcome = false;
mcapi.ListSubscribe(myMailChimpListId, email, merges, options);

Related

Amazon EventBridge rule cannot trigger a Lambda Function

Using the .Net AWSSDK.EventBridge I created a rule:
var client = new AmazonEventBridgeClient();
string ruleName = "SomeRule";
var putRuleRequest = new Amazon.EventBridge.Model.PutRuleRequest()
{
Name = ruleName,
ScheduleExpression = "rate(10 minutes)",
State = RuleState.ENABLED
}
await client.PutRuleAsync(putRuleRequest);
var target = new Amazon.EventBridge.Model.Target();
target.Arn = "ARN_LAMBDA_FUNCTION";
target.Id = "LAMBDA_FUNCTION_NAME";
target.Input = JsonSerializer.Serialize(new { someId, someDate});
var targetList = new List<Amazon.EventBridge.Model.Target>();
targetList.Add(target);
var putTargetRequest = new Amazon.EventBridge.Model.PutTargetsRequest()
{
Rule = ruleName,
Targets = targetList
};
await client.PutTargetsAsync(putTargetRequest);
The Lambda function is already created so I put the ARN and name on the Target. The idea is that there is one function but multiple rules will call it.
The rule, schedule, and target to the function are created when I run the code but the problem is that the function can't be triggered by the rule. When I edit the rule, update it in the AWS Console without changing anything the trigger works.
What am I missing?
After searching through I found out I was missing the permission for Lambda.
//This line replaces the code above
var putRuleResponse = client.PutRuleAsync(putRuleRequest).Result;
var lp = new Amazon.Lambda.Model.AddPermissionRequest();
lp.FunctionName = FUNCTION_ARN;
lp.Action = "lambda:InvokeFunction";
lp.SourceArn = putRuleResponse.RuleArn;
lp.Principal = "events.amazonaws.com";
lp.StatementId = "SomeStatement";
var lambdaClient = new AmazonLambdaClient();
await lambdaClient.AddPermissionAsync(lp);

Saved search returns no results programmatically

I have the following code:
var search = new TransactionSearchAdvanced();
search.savedSearchId = "680";
SearchResult searchResult = Client.Service.search(search);
var resultList = searchResult.searchRowList;
var castList = resultList.Cast<TransactionSearchRow>();
Everytime I call this method I get 0 search results returned. If I view the saved search in NetSuite itself I have over 1000 results.
I am running a similar search on customers that is 100% working.
public static List<Account> GetCustomerList()
{
var search = new CustomerSearchAdvanced();
search.savedSearchId = "678";
try
{
SearchResult searchResult = Client.Service.search(search);
var resultList = searchResult.searchRowList;
var castList = resultList.Cast<CustomerSearchRow>();
var accountList = new List<Account>();
foreach (var resultRow in castList)
{
var basic = resultRow.basic;
var account = new Account();
account.NsAccountId = basic.entityId?.FirstOrDefault()?.searchValue;
account.Name = basic.companyName?.FirstOrDefault()?.searchValue;
account.EmailAddress1 = basic.email?.FirstOrDefault()?.searchValue;
account.Address = basic.address?.FirstOrDefault()?.searchValue;
account.BillingAddress = basic.billAddress?.FirstOrDefault()?.searchValue;
account.Telephone1 = basic.phone?.FirstOrDefault()?.searchValue;
account.BillingPhone = basic.billPhone?.FirstOrDefault()?.searchValue;
account.Fax = basic.fax?.FirstOrDefault()?.searchValue;
account.WebAddress = basic.url?.FirstOrDefault()?.searchValue;
accountList.Add(account);
}
return accountList;
}
I have tried adding the the role to view transactions. I am totally unfamiliar with netsuite itself and have no idea what it could be since all the settings on my 2 searches are identical.
EDIT
The SearchResult objects are actually different:
looking into this now
In the saved search interface of NetSuite there is a field that needs to be chacked "Run Unrestricted" this is what solved it for me.

AdWords Get UserLists null entries but 17 items inside?

I am trying to get the list of UserLists on the account, but I get no entries even though during debugging the TotalNumOfEntries is 17. Screen shot is attached, any ideas why I cant see what these entries are? (sorry the details of debugger came out faint)
Code:
AdwordsUserListService usrService = (AdwordsUserListService)user.GetService(AdWordsService.v201402.AdwordsUserListService);
Selector usrSelect = new Selector();
usrSelect.fields = new String[] { "Id","Name", "Size", "MembershipLifeSpan" };
//Use predicates for filtering, if needed, later.
//Predicate usrPredicate = new Predicate();
//usrPredicate.field = "Name";
//usrPredicate.#operator = PredicateOperator.STARTS_WITH;
//usrPredicate.values = new string[] { "Poly" };
//usrSelect.predicates = new Predicate[] { usrPredicate };
usrSelect.paging = new Paging();
usrSelect.ordering = new OrderBy[] { new OrderBy() { field="Name",sortOrder=SortOrder.ASCENDING} };
UserListPage userListResult = usrService.get(usrSelect);
if (userListResult.entries != null)
{
return "Yay!";
}
Found my problem, I specified paging but didn't specify how many entries, adding this line fixed the problem.
usrSelect.paging.numberResults = 20;

Search by category Exchange Server EWS

I need to get all the emails that have a specific category name, how would I do this?
Right now I have this:
var col = new List<SearchFilter>();
col.Add(new SearchFilter.ContainsSubstring(ItemSchema.Categories, "Processed"));
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, col.ToArray());
FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox,
filter,
new ItemView(10)
);
But that gives me a Microsoft.Exchange.WebServices.Data.ServiceResponseException that says {"The Contains filter can only be used for string properties."}
How would I do it?
AFAIK as of Exchange 2010, category is a multi value field so it does not work with search filters. However, you can search categories using AQS. The following code should do the trick.
ExchangeService service = GetService();
var iv = new ItemView(1000);
string aqs = "System.Category:Processed";
FindItemsResults<Item> searchResult = null;
do
{
searchResult = service.FindItems(WellKnownFolderName.Inbox, aqs, iv);
foreach (var item in searchResult.Items)
{
Console.WriteLine(item.Subject);
}
iv.Offset += searchResult.Items.Count;
} while (searchResult.MoreAvailable == true);
I use the following code, to find all messages, which do NOT have set the category "Processed" and which have been received after a given date.
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
new SearchFilter.Not(new SearchFilter.IsEqualTo(EmailMessageSchema.Categories, "Processed")),
new SearchFilter.IsGreaterThan(EmailMessageSchema.DateTimeReceived, minDate));

Amazon Product Advertising API - searching for multiple UPCs

Using the Amazon Product Advertising API I am searching for 2 different UPCs:
// prepare the first ItemSearchRequest
// prepare a second ItemSearchRequest
ItemSearchRequest request1 = new ItemSearchRequest();
request1.SearchIndex = "All";
//request1.Keywords = table.Rows[i].ItemArray[0].ToString();
request1.Keywords="9120031340270";
request1.ItemPage = "1";
request1.ResponseGroup = new string[] { "OfferSummary" };
ItemSearchRequest request2 = new ItemSearchRequest();
request2.SearchIndex = "All";
//request2.Keywords = table.Rows[i+1].ItemArray[0].ToString();
request2.Keywords = "9120031340300";
request2.ItemPage = "1";
request2.ResponseGroup = new string[] { "OfferSummary" };
// batch the two requests together
ItemSearch itemSearch = new ItemSearch();
itemSearch.Request = new ItemSearchRequest[] { request1,request2 };
itemSearch.AWSAccessKeyId = accessKeyId;
// issue the ItemSearch request
ItemSearchResponse response = client.ItemSearch(itemSearch);
foreach (var item in response.Items[0].Item)
{
}
foreach (var item in response.Items[1].Item)
{
}
Is it possible to combine these two separate requests into one request and just have the first request return 2 items by setting keywords = "9120031340256 and 9120031340270"
Does anyone know how to do this?
Do I need to specifically search the UPC?
From looking at the API docs I think you may want to use an ItemLookup if you want to get results for multiple UPCs.
ItemLookup itemLookup = new ItemLookup(){
AssociateTag = "myaffiliatetag-20"
};
itemLookup.AWSAccessKeyId = MY_AWS_ID;
ItemLookupRequest itemLookupRequest = new ItemLookupRequest();
itemLookupRequest.IdTypeSpecified = true;
itemLookupRequest.IdType = ItemLookupRequestIdType.UPC;
itemLookupRequest.ItemId = new String[] { "9120031340300", "9120031340270" };
itemLookupRequest.ResponseGroup = new String[] { "OfferSummary" };
itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest };
ItemLookupResponse response = client.ItemLookup(itemLookup);
foreach(var item in response.Items[0])
{
//Do something...
Console.WriteLine(item.ItemAttributes.Title);
}
That being said, if you are not working with lookups by some ID (UPC, ASIN, etc) your original code of doing batched keyword searches appears to be only way to make multiple keyword searches in a single request (that I could find..). If doing keyword searches you could always make a ItemSearchRequest generator method to cut down on duplicate code when creating multiples.
You can use the following nuget
package.
PM> Install-Package Nager.AmazonProductAdvertising
Example
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.GetItemsAsync(new string[] { "B00BYPW00I", "B004MKNBJG" });

Categories