PHP Examples

The following examples are ready to use PHP code pieces for page, page block, and app function.

Page

<span class="token comment" spellcheck="true">// Set the content type to JSON</span>
<span class="token function">header</span><span class="token punctuation">(</span><span class="token string">'Content-Type: application/json'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Getting the action parameter</span>
<span class="token variable">$action</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">'action'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Checking the action of the parameter</span>
<span class="token comment" spellcheck="true">// If it is not 'activate', then echo unsuccessful JSON response.</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$action</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token variable">$action</span> <span class="token operator">!=</span> <span class="token string">'activate'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'The "action" is not supported!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// Activating Lead App</span>
<span class="token comment" spellcheck="true">// Initialize the array</span>
<span class="token variable">$data</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Activation type value: page</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'activation_type'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'page'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// API key</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'api_key'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">'API_key'</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// Grab it from the GET params</span>

<span class="token comment" spellcheck="true">// Lead App configuration</span>

<span class="token comment" spellcheck="true">// Lead App name</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'name'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'My Lead App'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Access URL</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'url'</span><span class="token punctuation">]</span> <span class="token operator">=</span> 'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//www.example.com/my/app';</span>

<span class="token comment" spellcheck="true">// Location is one of the following:</span>
<span class="token comment" spellcheck="true">// dashboard, statistics, campaigns, agents_mng, calling_list_management, product, b2b_mng, qatab, inbound, general_settings</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'location'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'dashboard'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Iframe's height in pixels</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'height'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">700</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token comment" spellcheck="true">// Iframe's sandbox attribute from the following (multiple values separated by space):</span>
<span class="token comment" spellcheck="true">// allow-forms, allow-pointer-lock, allow-popups, allow-same-origin, allow-scripts, allow-top-navigation</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'sandbox'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'allow-same-origin allow-scripts'</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token variable">$data_string</span> <span class="token operator">=</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token variable">$data</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token variable">$ch</span> <span class="token operator">=</span> <span class="token function">curl_init</span><span class="token punctuation">(</span>'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//pygration.leaddesk.com/leadapps_proxy/api/activate/');</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_CUSTOMREQUEST</span><span class="token punctuation">,</span> <span class="token string">"POST"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_POSTFIELDS</span><span class="token punctuation">,</span> <span class="token variable">$data_string</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_RETURNTRANSFER</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_HTTPHEADER</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
    <span class="token string">'Content-Type: application/json'</span><span class="token punctuation">,</span>
    <span class="token string">'Content-Length: '</span> <span class="token punctuation">.</span> <span class="token function">strlen</span><span class="token punctuation">(</span><span class="token variable">$data_string</span><span class="token punctuation">)</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// HTTP response</span>
<span class="token variable">$result</span> <span class="token operator">=</span> <span class="token function">curl_exec</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// HTTP response status number</span>
<span class="token variable">$httpcode</span> <span class="token operator">=</span> <span class="token function">curl_getinfo</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLINFO_HTTP_CODE</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$httpcode</span> <span class="token operator">==</span> <span class="token number">200</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'Lead App has been activated!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'Lead App could not be activated!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

Page Block

<span class="token comment" spellcheck="true">// Set the content type to JSON</span>
<span class="token function">header</span><span class="token punctuation">(</span><span class="token string">'Content-Type: application/json'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Getting the action parameter</span>
<span class="token variable">$action</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">'action'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Checking the action of the parameter</span>
<span class="token comment" spellcheck="true">// If it is not 'activate', then echo unsuccessful JSON response.</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$action</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token variable">$action</span> <span class="token operator">!=</span> <span class="token string">'activate'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'The "action" is not supported!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// Activating Lead App</span>
<span class="token comment" spellcheck="true">// Initialize the array</span>
<span class="token variable">$data</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Activation type value: page_block</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'activation_type'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'page_block'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// API key</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'api_key'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">'API_key'</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// Grab it from the GET params</span>

<span class="token comment" spellcheck="true">// Lead App configuration</span>

<span class="token comment" spellcheck="true">// Lead App name</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'name'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'My Lead App'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Access URL</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'url'</span><span class="token punctuation">]</span> <span class="token operator">=</span> 'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//www.example.com/my/app';</span>

<span class="token comment" spellcheck="true">// Location is one of the following:</span>
<span class="token comment" spellcheck="true">// campaign-editor</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'location'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'campaign-editor'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Iframe's height in pixels</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'height'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">400</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token comment" spellcheck="true">// Iframe's sandbox attribute from the following (multiple values separated by space):</span>
<span class="token comment" spellcheck="true">// allow-forms, allow-pointer-lock, allow-popups, allow-same-origin, allow-scripts, allow-top-navigation</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'sandbox'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'allow-same-origin allow-scripts'</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token variable">$data_string</span> <span class="token operator">=</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token variable">$data</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token variable">$ch</span> <span class="token operator">=</span> <span class="token function">curl_init</span><span class="token punctuation">(</span>'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//pygration.leaddesk.com/leadapps_proxy/api/activate/');</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_CUSTOMREQUEST</span><span class="token punctuation">,</span> <span class="token string">"POST"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_POSTFIELDS</span><span class="token punctuation">,</span> <span class="token variable">$data_string</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_RETURNTRANSFER</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_HTTPHEADER</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
    <span class="token string">'Content-Type: application/json'</span><span class="token punctuation">,</span>
    <span class="token string">'Content-Length: '</span> <span class="token punctuation">.</span> <span class="token function">strlen</span><span class="token punctuation">(</span><span class="token variable">$data_string</span><span class="token punctuation">)</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// HTTP response</span>
<span class="token variable">$result</span> <span class="token operator">=</span> <span class="token function">curl_exec</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// HTTP response status number</span>
<span class="token variable">$httpcode</span> <span class="token operator">=</span> <span class="token function">curl_getinfo</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLINFO_HTTP_CODE</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$httpcode</span> <span class="token operator">==</span> <span class="token number">200</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'Lead App has been activated!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'Lead App could not be activated!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

App Function

<span class="token comment" spellcheck="true">// Set the content type to JSON</span>
<span class="token function">header</span><span class="token punctuation">(</span><span class="token string">'Content-Type: application/json'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Getting the action parameter</span>
<span class="token variable">$action</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">'action'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Checking the action of the parameter</span>
<span class="token comment" spellcheck="true">// If it is not 'activate', then echo unsuccessful JSON response.</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$action</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token variable">$action</span> <span class="token operator">!=</span> <span class="token string">'activate'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'The "action" is not supported!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// Activating Lead App</span>
<span class="token comment" spellcheck="true">// Initialize the array</span>
<span class="token variable">$data</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Activation type value: app_function</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'activation_type'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'app_function'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// API key</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'api_key'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">'API_key'</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// Grab it from the GET params</span>

<span class="token comment" spellcheck="true">// Lead App configuration</span>

<span class="token comment" spellcheck="true">// Lead App name</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'name'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'My Lead App'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Access URL</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'url'</span><span class="token punctuation">]</span> <span class="token operator">=</span> 'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//www.example.com/my/app';</span>

<span class="token comment" spellcheck="true">// Location is one of the following:</span>
<span class="token comment" spellcheck="true">// admin.contact-lists.toolbar, admin.campaign-list.toolbar</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'location'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'campaign-admin.contact-lists.toolbar'</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// Iframe's height in pixels</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'height'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">400</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token comment" spellcheck="true">// Iframe's width in pixels</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'width'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">300</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token comment" spellcheck="true">// Iframe's sandbox attribute from the following (multiple values separated by space):</span>
<span class="token comment" spellcheck="true">// allow-forms, allow-pointer-lock, allow-popups, allow-same-origin, allow-scripts, allow-top-navigation</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'sandbox'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'allow-same-origin allow-scripts'</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// optional</span>

<span class="token comment" spellcheck="true">// Icon URL</span>
<span class="token variable">$data</span><span class="token punctuation">[</span><span class="token string">'config'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'icon'</span><span class="token punctuation">]</span> <span class="token operator">=</span> 'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//www.example.com/my/app/icon.png';</span>

<span class="token variable">$data_string</span> <span class="token operator">=</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token variable">$data</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token variable">$ch</span> <span class="token operator">=</span> <span class="token function">curl_init</span><span class="token punctuation">(</span>'https<span class="token punctuation">:</span><span class="token comment" spellcheck="true">//pygration.leaddesk.com/leadapps_proxy/api/activate/');</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_CUSTOMREQUEST</span><span class="token punctuation">,</span> <span class="token string">"POST"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_POSTFIELDS</span><span class="token punctuation">,</span> <span class="token variable">$data_string</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_RETURNTRANSFER</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_HTTPHEADER</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
    <span class="token string">'Content-Type: application/json'</span><span class="token punctuation">,</span>
    <span class="token string">'Content-Length: '</span> <span class="token punctuation">.</span> <span class="token function">strlen</span><span class="token punctuation">(</span><span class="token variable">$data_string</span><span class="token punctuation">)</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// HTTP response</span>
<span class="token variable">$result</span> <span class="token operator">=</span> <span class="token function">curl_exec</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// HTTP response status number</span>
<span class="token variable">$httpcode</span> <span class="token operator">=</span> <span class="token function">curl_getinfo</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLINFO_HTTP_CODE</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$httpcode</span> <span class="token operator">==</span> <span class="token number">200</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'Lead App has been activated!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    <span class="token keyword">echo</span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
        <span class="token string">'success'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'Lead App could not be activated!'</span>
    <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>