Ari
Ari

Reputation: 4979

Adding Custom Merge Tags in Mailchimp API 3.0

I have get around everywhere, but cannot find any clue to add custom merge tags through the api v3.0. The documentation seems to be very poor and cryptic.

I saw that in the previous version, it can be done through listMergeVarAdd() method.

What I want to do is adding any merge_tags dynamically.

How do I can add custom merge_tags through mailchimp api 3.0 for the use in a custom subscribe form?

Upvotes: 6

Views: 9904

Answers (2)

Ari
Ari

Reputation: 4979

Here is an example after some researches, may be someone will find it useful.

This is using VATPS Wrapper available here https://github.com/vatps/mailchimp-rest-api

$api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-usx";      
$mc = new MailChimp();
$mc->setApiKey($api_key);

    // Create Custom Merge Tags - Example           
    $result = $mc->post('/lists/{list-id}/merge-fields', array(
                    "tag" => "CUSTOM_SST",
                    "required" => false, // or true to set is as required 
                    "name" => "Custom Field",
                    "type" => "text", // text, number, address, phone, email, date, url, imageurl, radio, dropdown, checkboxes, birthday, zip
                    "default_value" => "", // anything
                    "public" => true, // or false to set it as not 
                    "display_order" => 2,
                    "help_text" => "I try to help you!"
                ));
    print_r($result);

    // Check If Merge Tags Already Exists - Example
    $result = $mc->get('/lists/{list_id}/merge-fields');
    print_r($result);

Upvotes: 1

TooMuchPete
TooMuchPete

Reputation: 4643

Since v3.0 is RESTful, you make a POST call to the /3.0/lists/{list_id}/merge-fields endpoint. The data you pass should match the List Merge Field Instance schema.

Upvotes: 3

Related Questions