<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Add Tag By Name &#8211; Chatbot Dojo</title>
	<atom:link href="https://v3.chatbotdojo.com/topic-category/add-tag-by-name/feed/" rel="self" type="application/rss+xml" />
	<link>https://v3.chatbotdojo.com</link>
	<description></description>
	<lastBuildDate>Wed, 13 Jan 2021 16:41:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.2</generator>

<image>
	<url>https://v3.chatbotdojo.com/wp-content/uploads/2020/07/favicon-56x56.png</url>
	<title>Add Tag By Name &#8211; Chatbot Dojo</title>
	<link>https://v3.chatbotdojo.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to assign a TAG to a subscriber with /fb/subscriber/addtagbyname</title>
		<link>https://v3.chatbotdojo.com/topic/how-to-assign-a-tag-to-a-subscriber-with-fb-subscriber-addtagbyname/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Fri, 08 Jan 2021 13:50:56 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com/?post_type=sfwd-topic&#038;p=25436</guid>

					<description><![CDATA[The curl command as displayed on the ManyChat API Swagger is: You need to replace the 0&#8217;s and &#8220;string&#8221; in the command with the appropriate data. I&#8217;ll show you how to use this and what it does below. The purpose of this API call is to assign a new TAG by NAME to your ManyChat &#8230;<p class="read-more"> <a class="" href="https://v3.chatbotdojo.com/topic/how-to-assign-a-tag-to-a-subscriber-with-fb-subscriber-addtagbyname/"> <span class="screen-reader-text">How to assign a TAG to a subscriber with /fb/subscriber/addtagbyname</span> Read More &#187;</a></p>]]></description>
										<content:encoded><![CDATA[
<p>The curl command as displayed on the ManyChat API Swagger is:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">curl -X POST "https://api.manychat.com/fb/subscriber/addTagByName" -H "accept: application/json" -H "Authorization: Bearer 0" -H "Content-Type: application/json" -d "{ \"subscriber_id\": 0, \"tag_name\": \"string\"}"</pre>



<p>You need to replace the 0&#8217;s and &#8220;string&#8221; in the command with the appropriate data. I&#8217;ll show you how to use this and what it does below.</p>



<p>The purpose of this API call is to assign a new TAG by NAME to your ManyChat subscriber. This API requires a Tag NAME which is a lot easier than the Tag ID. However the downside is if you use it via forms, the spaces or special characters in the form entry fields, may be altered by PHP. Forexample, a space might be translated into an underscore (_). If you use your own fixed code, or verification methods, you&#8217;ll fine fine!</p>



<blockquote class="wp-block-quote"><p>Your Tag must pre-exist</p></blockquote>



<h2>Why would you need this?</h2>



<p>The reasons for needing this, are obviously identical to those of the addTag via an ID. It&#8217;s just a different approach. If you want to TAG users for specific actions in your system, for example a completed step in your flow, this TAG has to pre-exist. With <a href="https://v3.chatbotdojo.com/topic/how-to-add-a-page-tag-with-page-createtag/" class="rank-math-link">this API call</a> you can create such a TAG automatically. Once your Tag is created, you can assign it to a user with this API. It&#8217;s a nice tool if you want to segment your users from your own CMS or (ecom) platform. You can document the entire path your user takes in your bot.</p>



<p>This is the default response on a successful request</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
  "status": "success"
}</pre>



<h2>So how do we use this in our own system?</h2>



<p>First we will add a new function to our class file in classes/manychat.class.php.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="879" data-enlighter-title="" data-enlighter-group="">    /**
     * 
     * @param type $subscriber_id
     * @param type $tag_name
     * @param type $mc_api
     * @return boolean
     */
    function subscriberAddTagByName($subscriber_id, $tag_name, $mc_api)
    {

        $postfields_arr = [
            'subscriber_id' => $subscriber_id,
            'tag_name'        => $tag_name
        ];

        $postfields = json_encode($postfields_arr);

        $ch            = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.manychat.com/fb/subscriber/addTagByName");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields . PHP_EOL);
        $headers       = [
            'Authorization: Bearer ' . preg_replace("/^(\w+\s+)/", "", $mc_api),
            'Content-Type: application/json',
            'Accept: application/json'
        ];
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $server_output = curl_exec($ch);
        curl_close($ch);

        $json_obj  = json_decode($server_output);
        $good_call = $json_obj->status;

        if ($good_call == "success") {
            return true;
        } else {
            return false;
        }
    }</pre>



<p>After we created the new function, we will create a new PHP file and call it <strong><em>subscriber_addtagbyname.php</em></strong>. It look like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/*
 * Load the ManyChat Config File
 */
require_once './config.inc.php';

/*
 * Set a Tag to a Subscriber with addTag by Name
 */

$subscriber_id     = "1929189923777499";
$tag_name            = "Received Coupon";
$subscriber_addtag = $mc->subscriberAddTagByName($subscriber_id, $tag_name, $mc_api);

if ($subscriber_addtag) {
    echo "Successfully added tag ID $tag_name to user $subscriber_id";
}</pre>



<p><code>$subscriber_addtag</code> will return TRUE for a correct response, which will allow us to report back the result.</p>



<p>What is your use case?</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
