<?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>remove tag by name &#8211; Chatbot Dojo</title>
	<atom:link href="https://v3.chatbotdojo.com/topic-tag/remove-tag-by-name/feed/" rel="self" type="application/rss+xml" />
	<link>https://v3.chatbotdojo.com</link>
	<description></description>
	<lastBuildDate>Thu, 14 Jan 2021 15:05:02 +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>remove tag by name &#8211; Chatbot Dojo</title>
	<link>https://v3.chatbotdojo.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to remove a TAG by name with /fb/subscriber/removeTagByName</title>
		<link>https://v3.chatbotdojo.com/topic/how-to-remove-a-tag-by-name-with-fb-subscriber-removetagbyname/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Mon, 11 Jan 2021 23:00:51 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com/?post_type=sfwd-topic&#038;p=25457</guid>

					<description><![CDATA[The curl command as displayed on the ManyChat API Swagger is: You need to replace the 0&#8217;s in the command with the appropriate data: ManyChat API key, subscriber ID, TagName (string). I&#8217;ll show you how to use this and what it does below. Why would you need this? I&#8217;ll quote the exact text from the &#8230;<p class="read-more"> <a class="" href="https://v3.chatbotdojo.com/topic/how-to-remove-a-tag-by-name-with-fb-subscriber-removetagbyname/"> <span class="screen-reader-text">How to remove a TAG by name with /fb/subscriber/removeTagByName</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/removeTagByName" -H "accept: application/json" -H "Authorization: Bearer 0" -H "Content-Type: application/json" -d "{ "subscriber_id": 0, "tag_name": 0}"</pre>



<p>You need to replace the 0&#8217;s in the command with the appropriate data: ManyChat API key, subscriber ID, TagName (string). I&#8217;ll show you how to use this and what it does below.</p>



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



<p>I&#8217;ll quote the exact text from the previous chapter here:</p>



<blockquote class="wp-block-quote"><p>This API is perfect for managing data in your platform or application. For example: you may have tagged your user for a certain interest or follow-up action. Once this action is marked as complete, you can remove the Tag automatically.</p></blockquote>



<p>Because this method is mostly the same as the Remove Tag by ID, I will not just duplicate the previous chapter and rename ID with Name, but I will make a combination of both methods, in one file.</p>



<p>This is the default response on a successful request, is, as always:</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>We are going to split this up in 2 parts again:<br>1. We are going to get all tags by the user ID and display them in a &#8220;double&#8221; list, so we can &#8230;<br>2. Click a link which will remove the specified Tag from the user, either by ID, or Name, whatever is preferred. We will make 2 different links for this in this file, which could replace the file from the previous chapter.</p>



<p>IF you have the chance to use the TagID, I recommend using that. Although it is more obvious you know the name of a tag by hand, it is also more prone to errors. In general, programming languages don&#8217;t like anything other than <em>aZ0-9_</em> in variable values.</p>



<p>Let&#8217;s First 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="961" data-enlighter-title="" data-enlighter-group="">    /**
     * 
     * @param type $tag_name
     * @param type $subscriber_id
     * @param type $mc_api
     * @return boolean
     */
    function subscriberRemoveTagByName($tag_name, $subscriber_id, $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/removeTagByName");
        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 2 new PHP files:</p>



<ol><li>subscriber_get_tags_by_id_and_name.php</li><li>subscriber_remove_tag_by_id_or_name.php</li></ol>



<p>The First file is to get a collection for the specific user, we display those for this time in a plain text list, with a hyperlink to delete them. It looks 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';

/*
 * Get the Subscriber Tags by Name AND Id
 */

$subscriber_id   = "1929189923777499";
$subscriber_info = $mc->getSubscriberInfo($subscriber_id, $mc_api);

$subscriber_tags = $subscriber_info->tags;

foreach ($subscriber_tags AS $tag) {
    echo "TAG name and ID" . $tag->name . " (" . $tag->id . ") &lt;a href='./subscriber_remove_tag_by_id_or_name.php?tag_id=" . $tag->id . "&amp;mc_uid=" . $subscriber_id . "'>Remove by ID&lt;/a> -- &lt;a href='./subscriber_remove_tag_by_id_or_name.php?tag_name=" . $tag->name . "&amp;mc_uid=" . $subscriber_id . "'>Remove by Name&lt;/a>&lt;br />"; 
}</pre>



<p>It you run this script in your browser, you&#8217;ll see something similar to this:</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-2.png" alt="" class="wp-image-25462" width="714" height="325" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-2.png 707w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-2-300x137.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-2-400x182.png 400w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-2-600x273.png 600w" sizes="(max-width: 714px) 100vw, 714px" /></figure>



<p>It doesn&#8217;t look nice, but if you put this little snippet of code inside a basic Bootstrap theme, it will immediately look great. Just wrap the hyperlinks in HTML Buttons instead of textlinks and add a little padding between the paragraph lines and voilá! </p>



<p>Now let&#8217;s create the PHP file for the links, so we can remove and cleanup the Tag. The second PHP file will look like this, note that I created a simple if&lt;&gt;else clause here to check what variable is sent through the link. Since the Id is most accurate, we look fo rthat First, if it is not there, we move on to the next clause and we finish with an exit routine if nothing is found:</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';

/*
 * Remove Subscriber TAG by Id or Name
 */

$clean_data          = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
$subscriber_tag_id   = $clean_data['tag_id'] ?? "";
$subscriber_tag_name = $clean_data['tag_name'] ?? "";
$mc_uid              = $clean_data['mc_uid'];

if (!empty($subscriber_tag_id)) {
    $subscriber_remove_tag = $mc->subscriberRemoveTag($subscriber_tag_id, $mc_uid, $mc_api);
    $subscriber_tag        = $subscriber_tag_id;
} elseif (!empty($subscriber_tag_name)) {
    $subscriber_remove_tag = $mc->subscriberRemoveTagByName($subscriber_tag_name, $mc_uid, $mc_api);
    $subscriber_tag        = $subscriber_tag_name;
} else {
    exit("No Tags set to remove");
}

if ($subscriber_remove_tag) {
    echo "Bingo! You removed the following Tag : " . $subscriber_tag . " from subscriber number " . $mc_uid;
} else {
    echo "We could not remove your Tag";
}</pre>



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



<p>So, when we click the <code>Remove by Name</code> link for <code>TAG Name and ID Language Preference is English (16205530)</code> from the Tag list above, we get this result:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="776" height="51" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-3.png" alt="" class="wp-image-25465" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-3.png 776w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-3-300x20.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-3-768x50.png 768w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-3-400x26.png 400w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-3-600x39.png 600w" sizes="(max-width: 776px) 100vw, 776px" /></figure>



<p>Pretty handy, right?</p>



<p>Next, we are going to set Custom fields, a very common and much used API.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
