How to update campaigns content with template in mailchimp - templates

I want to use mailchimp to send mail when something happen automatically , so i use mailchimp restful api to do this:
1.Create a campaign with api /campaigns
2.Update the campaign with api /campaigns/{campaign_id}/content
3.Send the campaign
in this second step, i found the API /campaigns/{campaign_id}/content can update the campaign's content with plaintext or html easy with http body like this:
{"html": "<p>The HTML to use for the saved campaign<./p>"}
but i am not sure how to use a template to update the content.
In the API document(https://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/content/#), if you want to use template update content, you need fill the template id and template sections, but how do i know the sections in a template?
I try to use the template api to get a template detail information, in the response, the section filed is empty array.
any suggestion? or give me example!
thank you guys
Regard to great developers

Not sure if you ever found an answer, but I am struggling with this API too. The sections can be retrieve from the GetDefaultContent API which will return an MailChimp Response with a sections object. That object, in turn, will have all the sections that you have specified in your template by name and their default content.
I am still trying to figure out the updating part, myself, but hope this helps a bit.

Related

Correct approach to creating API endpoints

I'm creating an API in Django Rest Framework and i'm thinking about best approach to provide actions like adding a post to user reading list. Firstly i've done it by GET request, because it was looking most natural and url for example looks like /api/posts/{id}/add_to_reading_list/. Now i recognized that GET should be used only to retrieve data so i've changed it to POST method and now url is looking like /api/posts/add_to_reading_list/. The first thing is that i needed to create new serializer specially to handle this action which accepts only id field, because this endpoint should accept only already created posts. Is it how it should be done? I was thinking about sending whole post object in POST method, but doesn't it a waste of bandwidth when i need only id? It will prevent me of creating a new serializer for this specific case, but i don't think that it is a correct approach.

Edit a template inside the embedded console. Like: /templates/{templateId}/views/edit

We are using the DocuSign API to create Templates. To edit the template, we get the embedded console url, and navigate to Templates, find the template we want to edit, and the select edit. Is there a way to get a url to directly edit the template inside the embedded console? Something like: /templates/{0}/views/edit
Absolutely you can, do a Post Sender view but replace the envelope ID with the template ID and it will give you the URL to a session where you can modify the template.

How to add another option to the share functionality of Google Glass?

I am interested to add my service into the share functionality of the Google Glass, my flow is below:
1. Take photo / Record video
2. Share with -> My service
3. the photo or video should be uploaded to my site
Is this functionality possible? it is very similar to Facebook and G+ share options.
I will be happy to know how to do it, Thanks.
What you are looking for is what the Mirror API calls a Contact. Your Glassware can setup one or more Contacts, specifying what content type can be shared with you and/or if there are voice commands which will trigger the Contact.
You will also need to setup a Subscription which will be the public URL for an HTTPS enabled server that the Mirror API will use to send you the content that was shared with the Contact.
In general, the flow when a user first authorizes you to write to their time would be something like this:
Add a Subscription, so you can get callbacks.
Add one or more Contacts. In your example, you would want to register the Contacts to have acceptTypes of image/* and video/*, although you can also omit the acceptTypes to get everything (including text).
The callback you register with the subscription should be able to handle a JSON body, and should return HTTP code 200 as quickly as possible. A good procedure is to actually accept the body, place it on a job queue for processing later, and immediately return the 200 code. When processing the body, you may want to do something like
Confirm the userToken and verifyToken provided are valid.
Using the itemId, get the Timeline item, which will include attachment information about what was shared with you.
If the attachment is marked as isProcessingContent, then the content isn't ready for you and you should return the job to the queue and try again soon.
If isProcessingContent is false, you can use the attachment URL with the authentication token for the user to fetch the content itself.
There are a lot of details I've glossed over here. For a further overview of the flow, see https://developers.google.com/glass/develop/mirror/contacts

HTML rich email invitation with RSVP button to database?

What I am trying to do is this:
Send an invitation for an event via HTML eblast. I would like the users to be able to RSVP straight from the email (click Yes, No, Maybe) and by doing so, will send that info into a database for my client to view the responses.
They specifically do not want responses coming in as emails, they want to view it as a list, and does not want to use something like evite. I've looked everywhere but don't see how to do this. Any thoughts? Thanks in advance!
I believe you would need to dynamically generate an email message for each recipient.
You would alter the Yes/No/Maybe URLs for each recipient so it sends their information to a web page (php/aspx/whatever) that then adds their selection to your database.
So you would loop through your list of recipients, generate the email with a variable altering the url of your Yes/No/Maybe links to something like http://yoursite.com/rsvp.php?user=<TheUsersName>&selection=<YesNoOrMaybe>.
Then just have that rsvp.php page set up to pull the GET variables you passed with the link and add them to your database.

using POST request on Facebook Graph API

I want to access graph API to get the number of shares for different pages of my website. I can use the GET method to do so but I want to use POST so that I can send more url in a single request. The current implementation I have for GET is
http://graph.facebook.com/?ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/
Can anyone please help ?
This is badly documented (I mean I didn't find the information when I looked for it!), but there is way to pass all the parameters to the Graph API through POST method:
in your example, you should POST to http://graph.facebook.com/
with the following DATA:
ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/&method=GET
I'm not sure about the encoding of the POST DATA..in our case, we were just using ids=.....,.....,..... with numeric FB user ids and we didn't need to do any encoding, but you might need some url-encoding
Don't forget the &method=GET or it won't work ! It helped me break the url length limit that was causing bugs on Internet Explorer (I think RFC says 1024 characters, all browsers support much more, IE only ~4096 ) when we were passing too many ids through GET
if you wish to access non-public information, the same trick works with https://graph.facebook.com/ , provided you add &session_token=***** to your query
You can try to run a FQL query to get the stats for multiple urls. Facebook link_stat documentation has an example of how to do this. I'm pretty sure you can't POST to either the FQL query or the graph api you were using though unfortunately. Your FQL query would be:
SELECT url, share_count, like_count FROM link_stat WHERE url IN("http://umairj.com/","http://umairj.com/146/how-to-clear-facebook-shares-cache/")
Here is the url after properly url encoding the query: https://api.facebook.com/method/fql.query?query=SELECT+url%2C+share_count%2C+like_count+FROM+link_stat+WHERE+url+IN%28"http%3A%2F%2Fumairj.com%2F"%2C"http%3A%2F%2Fumairj.com%2F146%2Fhow-to-clear-facebook-shares-cache%2F"%29&format=json
Facebook provides a FQL testing tool to help.
Update: their API documention (see section titled "Delete) mentions you can do an HTTP POST to any of their methods and set the variable method to the method you want. You could try this, although this was designed for delete and put methods not available to javascript clients. It still looks like is all url based so I'm not sure it will take a form encoded parameter like you are looking to do.
I work at Facebook and I've updated our Graph API documentation to document this work around for very large requests:
https://developers.facebook.com/docs/graph-api/using-graph-api#largerequests