<?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>Get Tags &#8211; Chatbot Dojo</title>
	<atom:link href="https://v3.chatbotdojo.com/topic-category/get-tags/feed/" rel="self" type="application/rss+xml" />
	<link>https://v3.chatbotdojo.com</link>
	<description></description>
	<lastBuildDate>Sat, 22 Aug 2020 15:20:00 +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>Get Tags &#8211; Chatbot Dojo</title>
	<link>https://v3.chatbotdojo.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to get all Page TAGS with /fb/page/getTags</title>
		<link>https://v3.chatbotdojo.com/topic/how-to-get-all-page-tags-with-fb-page-gettags/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Fri, 21 Aug 2020 11:05:23 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com/?post_type=sfwd-topic&#038;p=25119</guid>

					<description><![CDATA[The curl command as displayed on the ManyChat API Swagger is: The purpose of this API call is to GET all TAGS currently in your ManyChat account. Why would you need this? A use case could be: if you have a platform where people can be tagged, you can use this list of available TAGS &#8230;<p class="read-more"> <a class="" href="https://v3.chatbotdojo.com/topic/how-to-get-all-page-tags-with-fb-page-gettags/"> <span class="screen-reader-text">How to get all Page TAGS with /fb/page/getTags</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 GET "https://api.manychat.com/fb/page/getTags" -H "accept: application/json"</pre>



<p>The purpose of this API call is to GET all TAGS currently in your ManyChat account.</p>



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



<p>A use case could be: if you have a platform where people can be tagged, you can use this list of available TAGS as a reference in a webform select menu.</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="3,6,10" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
  "status": "success",
  "data": [
    {
      "id": 0,
      "name": "string1"
    },
    {
      "id": 1,
      "name": "string2"
    }
  ]
}</pre>



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



<blockquote class="wp-block-quote"><p>We assume you started in the First chapter of this course, and are now aware of the creation of the class file and the config file.<br>Those files are being used in ALL scripts we explain in the course. If you missed it, <a href="https://v3.chatbotdojo.com/topic/fb-page-getinfo/">go here</a> and read it.</p></blockquote>



<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="81" data-enlighter-title="" data-enlighter-group="">    /**
     * 
     * @param type $mc_api
     * @return type
     */
    function getPageTags($mc_api)
    {

        $ch            = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.manychat.com/fb/page/getTags");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $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") {
            usort($json_obj->data, function($a, $b) {
                return strcmp($a->name, $b->name);
            });
            $tags = [];
            foreach ($json_obj->data as $mc_page_tags) {
                $tags[$mc_page_tags->name] = $mc_page_tags->name;
            }
            return $tags;
        }
    } </pre>



<p>After we created the new function, we will create a new PHP file and call it <strong><em>page_get_tags.php</em></strong>. Here&#8217;s the start of our new PHP file:</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 TAGS for your page
 */

// add functions here</pre>



<p>We will add a call to the function from the class file now, and display all TAGS in alphabetical (we used an anonymous function to sort the keys by name) order. We will do that as follows.</p>



<p>First, we add this line:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="12" data-enlighter-title="" data-enlighter-group="">$page_tags = $mc->getPageTags($mc_api);

foreach($page_tags AS $tag){
    echo $tag . "&lt;br />";
}</pre>



<p>Now, when we run the file (<strong><em>page_get_tags</em>.<em>php</em></strong>) in our browser, we should see the result as a long list of your page tags:</p>



<p>That&#8217;s great! We successfully retrieved all TAGS in the ManyChat system, all in our own environment! </p>



<p>We used the <strong><em>foreach </em></strong>loop to iterate through the <strong><em>Array </em></strong>that was created in our class  function. If you need more information about how foreach functions work, please check this link on php.net:</p>



<ul><li>foreach &#8211; <a href="https://www.php.net/manual/en/control-structures.foreach.php" target="_blank" rel="noopener">https://www.php.net/manual/en/control-structures.foreach.php</a></li></ul>



<p>We now have a fully functional script that gets all your TAGs, all from our own localhost, or server. That was cool, right?</p>



<p>The full PHP script now 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 TAGS for your page
 */

$page_tags = $mc->getPageTags($mc_api);

foreach($page_tags AS $tag){
    echo $tag . "&lt;br />";
}</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
