MailChimp v3 API - Adding to Groups - mailchimp

Is there a way to manage a subscribers' group preference for lists in the v3 API? MailChimp documentation is a little light on the subject.

Yes, by assigning the member to an interest.
You have to find out the ID of the group (called 'interests') that you are wanting to add to. Unfortunately this cannot be found anywhere on the MailChimp dashboard.
The easiest way to find out the 'interest' ID (rather than creating a script) is to go to the MailChimp playground and then, after entering in your API key, route to...
lists > the list in question > members (in the sub-resources dropdown)
then...
load (in the actions dropdown) for any member
or
Create Members (button)
The page will load the member's details. Scroll down until you see the 'interests' array/object. There you will see the IDs. Notice they can be set to true or false.
You will have to figure out which ID relates to what 'group'/'interest' by making the call, and then looking at the member's details via your MailChimp dashboard.
So when it comes to actually making the POST call ('member' create), you would want something on the lines of...
{
"email_address":"example#freddiesjokes.com",
"status":"subscribed",
"interests": {
"b8a9d7cbf6": true
},
# ADDITIONAL FIELDS, IF REQUIRED...
"merge_fields":{
"FNAME": "foo bar",
"LNAME": "foo bar",
"MERGE3": "foo bar",
"MERGE4": "foo bar"
}
}
A PUT call ('member' edit) example...
{
"interests": {
"b8a9d7cbf6": false,
"5998e44916": true
}
}
For PUT requests, it seems that you must declare every 'interest' and state whether it is true or false.

I think this is what you are looking for: Lists Interest Categories Collection
In that endpoint you can get and create new groups for lists. And here Lists Interests Collection you can get interests or create new ones.
Lemonades
Coca Cola
Pepsi Max
Fanta
Lemonades represents category or better a group name. Cola, pepsi and fanta represents interests or better group items in that spesific group/category.
Hope this helps :)

Related

Get list of shipping methods for a subsidiary

I'm using NetSweet/NetSuite Ruby gem for connecting to NetSuite accounts.
Normally it's trivial to get list of shipping methods using get_select_value. However one NetSuite account is organized into subsidiaries, and shipping methods are assigned to subsidiaries. For this particular account, get_select_value returns empty list:
NetSuite::Records::BaseRefList.get_select_value({
recordType: "salesOrder",
field: "shipMethod",
}).base_refs.length
=> 0
This makes some sense: in new sales order form the list of shipping methods is initially empty. When I select "customer" option, NetSuite automatically fills the read-only field "subsidiary". Then list of available shipping methods is populated.
Is there a way to fetch list of shipping methods by subsidiary or for a customer?
NetSuite API response contains a warning: "Results are incomplete. You must provide a value for field entity."
Full response:
<getSelectValueResponse xmlns="urn:messages_2016_2.platform.webservices.netsuite.com">
<platformCore:getSelectValueResult xmlns:platformCore="urn:core_2016_2.platform.webservices.netsuite.com">
<platformCore:status isSuccess="true">
<platformCore:statusDetail type="WARN">
<platformCore:code>WARNING</platformCore:code>
<platformCore:message>Results are incomplete. You must provide a value for field entity.</platformCore:message>
</platformCore:statusDetail>
</platformCore:status>
<platformCore:totalRecords>0</platformCore:totalRecords>
<platformCore:totalPages>0</platformCore:totalPages>
</platformCore:getSelectValueResult>
</getSelectValueResponse>
Using filterByValueList and passing customer internalId as entity seems to work.
NetSuite::Records::BaseRefList.get_select_value({
recordType: "salesOrder",
field: "shipMethod",
filterByValueList: {
"platformCore:filterBy" => {
"platformCore:field" => "entity",
"platformCore:internalId" => ns_customer.internal_id}
}
}).base_refs.length
=> 17
It's somewhat counter-intuitive, as filter option should reduce items in the output.
Generated XML:
<platformMsgs:getSelectValue>
<platformMsgs:pageIndex>1</platformMsgs:pageIndex>
<platformMsgs:fieldDescription>
<platformCore:recordType>salesOrder</platformCore:recordType>
<platformCore:field>shipMethod</platformCore:field>
<platformCore:filterByValueList>
<platformCore:filterBy>
<platformCore:field>entity</platformCore:field>
<platformCore:internalId>4978501</platformCore:internalId>
</platformCore:filterBy>
</platformCore:filterByValueList>
</platformMsgs:fieldDescription>
</platformMsgs:getSelectValue>

CouchDB 2.0 - How to autoincrement keys in a View?

In CouchDB 2.0, I'm trying to create an ordered list as the keys from a View, but it doesn't work.
My code for the View document:
var i = 0;
function (doc) {
if (doc.type === "comment") {
emit(i++, doc.webpages);
}
}
The result is that all keys are equal to 0. How can I make it so that each document gets an autoincremented key?
Thanks!
A sequential ID probably isn't the best choice for most real applications. For example, if you were to build a commenting system I would approach it like this (there's a similar example in the couch docs):
Comments would be docs with a structure like this:
{
"_id": "comment_id",
"parent":"comment_id, or article_id if a top level comment"
"timestamp" : "iso datetime populated by the server",
"user_id": "the person who wrote the comment",
"content": "content of the comment"
}
To display all the top level comments of a given parent (either article or parent comment), you could use a view like this:
def function(doc){
emit([doc.parent, doc.timestamp, doc.user_id], doc._id)
}
To query this efficiently, you'd could use the following query options to grab the first twenty:
{
"startkey": ["parent_id"],
"endkey": ["parent_id", {}],
"limit": 20,
"skip": 0,
"include_docs": true
}
The comments will automatically be sorted by the date they were posted because the view is ordered by [parent, datetime, and then user]. You don't have the pass a value for anything other than parent with your key for benefit from this.
Another thing of note is by not passing the content of the comment to the view and instead using include_docs, your index will remain as slim as possible.
To expand on this:
If you want to show replies to a base comment, you can just change
the start and end keys to that comment's id.
If you want to show the next 20 comments, just change skip to 20.
If you want more comments shown initially, just up the limit value.
In answer to your comment, if you had an array or parents in your document like:
"parents" : ["a100", "a101", "a102"]
Everything else would remain the same, except you would emit a row for each parent.
def function(doc){
doc.parents.map( function (parent){
emit([doc.parent, doc.timestamp, doc.user_id], doc._id)
});
}

VK Web API (simple)

I would like to call the method "photos.get" and retrieve photos from a VK community.The problem is that I am unable to view the oid i.e owner_id( one of the parameters required for the request) when I visit the URL. For example, when I browse a certain community, I end up getting a URL like "http://vk.com/picsa".Instead of this picsa, I require a number that can be passed in as an argument. How do I get the owner_id instead from the URL?
You can use groups.getById API method. It does not require any authentication:
https://api.vk.com/method/groups.getById?group_ids=picsa
You will get the default group entity in JSON format:
{
"response": [
{
"gid": 37460919,
"name": "AMERICA",
"screen_name": "picsa",
"is_closed": 0,
"type": "page",
// photos of different size go here
}
]
}
Now, you can extract the community's ID (gid) and will be able to use it in other API requests. You can get information about several communities at the same time - you need to enumarate them with commas (/method/groups.getById?group_ids=picsa,othergroup,somename).
When you work with photos.get method, keep in mind, that VK uses negative ID values for communities and pages.
For example,
/method/photos.get?owner_id=123456789 means "photos of user 123456789" and
/method/photos.get?owner_id=-123456 means "photos of community 123456".
Other way to get group id when there is no it in group link is to click on post date of any post on the wall
And in the address line you will see link like
https://vk.com/picsa?w=wall-37460919_47702
So 37460919 is group id you need

MongoDB pagination with grouped item

I am building a messaging module into an existing web app. We are storing the messages in mongo with a data structure that something looks like:
{
id: "",
inResponseToMessageId: ""
to: []
cc: []
bcc: []
subject: ""
body: ""
owners: [{id:4, status:"read", folder:"inbox"}, {id:1, status:'unread', folder:'inbox'}]
dateSent:
}
The client would like us to be able to display messages in both a conversation view and a singleton view.
I am having trouble figuring out an efficient query that can
Return results grouped by message thread.
Work well with pagination.
Sortable by date and subject.
I can modify the data structure however I need in order to get this to work well.
Below are a few possible solutions but they all seem to fall short:
Store messages as children of a thread object.
Add a threadId to each message and then query and group by threadId.
Create some type of meta information object that helps.
The problem with the standard mongo group or $group function is that I imagine it will perform very poorly when the collection is large. We are expecting there to be hundreds of millions of messages in the collection.
Put a threadId on your messages.
Return results grouped by message thread.
You can find messages by thread like
db.messages.find({ "threadId" : id })
I don't think there's any need to group them in the sense of the $group operator.
Work well with pagination.
Pagination for the messages in what order? Pagination works well if you have a sort on a unique field. dateSent should be unique if you keep it to millisecond precision, so you can paginate on it.
// page 1
db.messages.find({ "threadId" : id }).sort({ "dateSent" : -1 }).limit(25)
// page 2
db.messages.find({ "threadId" : id, "dateSent" : { "$gt" : <25th date sent> } }).sort({ "dateSent" : -1 }).limit(25)
Sortable by date and subject.
Who sorts messages by subject? Anyway, this is just a matter of creating the right indexes if you want to retrieve messages in date or subject order. Depending on your requirements you might be doing this sorting for a client view, where it might not be necessary to have the database sort the results. The client could do it for the returned subset instead.

How to set same meta data across collections?

Am trying to set a product category on different collections but only the last collection defined in docpad.coffee actually sets it when trying it like so
firstCollection: ->
#getCollection("html").findAllLive().on "add", (model) ->
model.setMeta({category: 'first'})
secondCollection: ->
#getCollection("html").findAllLive().on "add", (model) ->
model.setMeta({category: 'second'})
document.categorywill be 'second' for all documents of each collection.
How to set the same meta data individually per doc in a collection?
What problem are you trying to solve? Because your approach is not going to work. If you share what you're trying to do, we may be able to suggest an alternative approach.
Your current approach won't work because you are setting a metadata property named "category" that is a string. That metadata property lives on the documents in the collection and not on the collection itself.
Both collections are pointing at the same set of documents. Each individual document can only have a single value for that property. It can't be both 'first' and 'second'. The last one to set it wins, and in this case, the event that sets it to 'second' is happening last and so all of the documents have 'second' as the value for that metadata property.
Update: I found a better way to do this: model.setMetaDefaults({foo:'bar'})
For example, to create a blog collection with a default cssClass of post:
collections: {
blog: function() {
return this.getCollection("documents")
.findAllLive({relativeOutDirPath:'blog'}, [{filename:-1}])
.on("add", function (model) {
model.setMetaDefaults({'cssClass': 'post'})
});
}
},
This would go in your docpad.coffee file or, in my case, docpad.js.
See a working example with full context at https://github.com/nfriedly/nfriedly.com/blob/master/docpad.js#L72 (collection is called "techblog", starts around like 72).

Resources