<?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>template api &#8211; Chatbot Dojo</title>
	<atom:link href="https://v3.chatbotdojo.com/topic-tag/template-api/feed/" rel="self" type="application/rss+xml" />
	<link>https://v3.chatbotdojo.com</link>
	<description></description>
	<lastBuildDate>Wed, 20 Jan 2021 10:42:32 +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>template api &#8211; Chatbot Dojo</title>
	<link>https://v3.chatbotdojo.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>List of Template API calls</title>
		<link>https://v3.chatbotdojo.com/topic/list-of-template-api-calls/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Sat, 16 Jan 2021 15:09:15 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com?post_type=sfwd-topic&#038;p=25609</guid>

					<description><![CDATA[POST /user/template/generateSingleUseLink]]></description>
										<content:encoded><![CDATA[
<p><span class="opblock opblock-summary-method-post">POST</span> /user/template/generateSingleUseLink</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to create a unique template link with generateSingleUseLink</title>
		<link>https://v3.chatbotdojo.com/topic/how-to-create-a-unique-template-link-with-generatesingleuselink/</link>
		
		<dc:creator><![CDATA[ninjawarrior]]></dc:creator>
		<pubDate>Sat, 16 Jan 2021 13:58:01 +0000</pubDate>
				<guid isPermaLink="false">https://v3.chatbotdojo.com/?post_type=sfwd-topic&#038;p=25594</guid>

					<description><![CDATA[The curl command as displayed on the ManyChat API Swagger is: If you use cUrl, change (Bearer) 0 with your ManyChat Profile API key, and put your template ID in the command, like \"template_id\": 123456798. Please note that for the Template API to work, you are NOT using the regular public API key, but your &#8230;<p class="read-more"> <a class="" href="https://v3.chatbotdojo.com/topic/how-to-create-a-unique-template-link-with-generatesingleuselink/"> <span class="screen-reader-text">How to create a unique template link with generateSingleUseLink</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/user/template/generateSingleUseLink" -H "accept: application/json" -H "Authorization: Bearer 0" -H "Content-Type: application/json" -d "{ \"template_id\": 0}"</pre>



<p>If you use cUrl, change (Bearer) 0 with your ManyChat <strong><em>Profile</em></strong> API key, and put your template ID in the command, like<code> \"template_id\": 123456798</code>.</p>



<p>Please note that for the Template API to work, you are NOT using the regular public API key, but your PROFILE API key. You can find that in the following path: <em>My Profile &gt; Settings</em></p>



<figure class="wp-block-image size-large"><img loading="lazy" width="987" height="793" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-24.png" alt="" class="wp-image-25597" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-24.png 987w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-24-300x241.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-24-768x617.png 768w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-24-373x300.png 373w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-24-600x482.png 600w" sizes="(max-width: 987px) 100vw, 987px" /></figure>



<p>The purpose of this API call is to create a one time use link for your template installation.</p>



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



<p>This is great if you do not want other people sharing your templates, with the use of this simple feature, the templates can only be installed one time. When the URL is used, the link is no longer valid.</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",
  "data": {
    "hash_code": "string",
    "installation_link": "string"
  }
}</pre>



<p>You can use the installation link anywhere on your pages, or autoload them in your chatbot after purchase.</p>



<h2>Let&#8217;s create a unique link</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="1274" data-enlighter-title="" data-enlighter-group="">    /**
     * 
     * @param type $template_id
     * @param type $mc_profile_api
     * @return type
     */
    function generateSingleUseLink($template_id, $mc_profile_api)
    {

        $bot_vars            = [
            'template_id' => $template_id
        ];
        $postfields_bot_vars = json_encode($bot_vars, JSON_NUMERIC_CHECK);

        $ch            = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.manychat.com/user/template/generateSingleUseLink");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields_bot_vars . PHP_EOL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $headers       = [
            'Authorization: Bearer ' . preg_replace("/^(\w+\s+)/", "", $mc_profile_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 $json_obj->data->installation_link;
        } else {
            return false;
        }
    }</pre>



<p>After we created the new function, we will create a new PHP file and call it <strong><em>template_generate_single_use_link.php</em></strong>. </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';

/*
 * Template Generate Single Use Link
 */

$template_id = filter_input(INPUT_GET, 'tpl', FILTER_VALIDATE_INT);

$template_id ?: exit('A template Id is obligatory');
$uniqueLink  = $mc->generateSingleUseLink($template_id, $mc_profile_api);

if ($uniqueLink) {
    echo $uniqueLink;
}else{
    echo "/index.html";
}
</pre>



<p>The PHP file is very short and simple. All it needs to do is check if there&#8217;s a result and publish the new URL.</p>



<p>The URL can be called like <code>template_generate_single_use_link.php?tpl=123456</code> where 123456 is your template Id. You can find that here:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="978" height="648" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-28.png" alt="" class="wp-image-25604" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-28.png 978w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-28-300x199.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-28-768x509.png 768w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-28-400x265.png 400w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-28-600x398.png 600w" sizes="(max-width: 978px) 100vw, 978px" /></figure>



<p>Let&#8217;s call the URL and see what it returns in the browser:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="795" height="91" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-26.png" alt="" class="wp-image-25602" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-26.png 795w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-26-300x34.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-26-768x88.png 768w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-26-400x46.png 400w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-26-600x69.png 600w" sizes="(max-width: 795px) 100vw, 795px" /></figure>



<p>Calling the URL without a querystring, returns an error, we need to append a template Id, let&#8217;s retry:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="818" height="78" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-29.png" alt="" class="wp-image-25605" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-29.png 818w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-29-300x29.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-29-768x73.png 768w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-29-400x38.png 400w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-29-600x57.png 600w" sizes="(max-width: 818px) 100vw, 818px" /></figure>



<p>Bingo! As you can see we now get a nice single use template Id.</p>



<p>One more try, with a non existent template Id:</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="797" height="72" src="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-30.png" alt="" class="wp-image-25606" srcset="https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-30.png 797w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-30-300x27.png 300w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-30-768x69.png 768w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-30-400x36.png 400w, https://v3.chatbotdojo.com/wp-content/uploads/2021/01/image-30-600x54.png 600w" sizes="(max-width: 797px) 100vw, 797px" /></figure>



<p>See, it works perfectly fine. You can now use this API to generate a link in your source code by &#8211; for example &#8211; using it embedded in your hyperlink. </p>



<p>There are a million ways to do this, but I will edit the PHP script a bit, so we can use the URL of that script as the link in the HREF code. The new PHP file 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';

/*
 * Template Generate Single Use Link
 */

$template_id = filter_input(INPUT_GET, 'tpl', FILTER_VALIDATE_INT);

$template_id ?: exit('A template Id is obligatory');
$uniqueLink = $mc->generateSingleUseLink($template_id, $mc_profile_api);

if ($uniqueLink) {
    header('Location: ' . $uniqueLink);
    exit;
} else {
    header('Location: /index.html');
    exit;
}
</pre>



<p>Now you can easily use the link to that script, as the href URL anywhere in your code.</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;a href="template_generate_single_use_link.php?tpl=123456" target"_blank">Download Template&lt;/a></pre>



<p>When we click the link on the page now, we get sent to either the Template Installation page, or back to /index.html.</p>



<p>That wraps up the Template API, there is only one at this time. I hope it will benefit your ventures.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
