Jump to content

Stupid question, but how do I use Internal API in a template?


shout

Recommended Posts

I know this is a simple question, but I'm having trouble getting started--been struggling through the documentation and searching this forum for a while.

 

This page in the documentation says:

 

The internal API can be used from any file within WHMCS - be it a template, action hook, addon module, anything.

 

So I know it's possible to use the internal API in a template. However, when I try to do it, it doesn't work. The Internal API example code is PHP, doesn't work in the templates.

 

<?php

# Set Vars
$command = 'SendEmail';
$values = array( 'messagename' => 'Test Template', 'id' => '1', );
$adminuser = 'DemoAdmin';

# Call API
$results = localAPI($command,$values,$adminuser);
if ($results['result']!="success") echo "An Error Occurred: ".$results['result'];

?>

 

Putting that directly in a template just results in it getting commented out. So I created test.php in the root WHMCS folder, put that code in it, and tried calling it from within a template with a form, but I got this error:

 

Fatal error: Call to undefined function localAPI() in /path/to/file/test.php on line 9

 

Where is the demo code for the API supposed to go, and how do I call it??

Link to comment
Share on other sites

Try changing it to the following, in your template:

 

{php}

# Set Vars
$command = 'SendEmail';
$values = array( 'messagename' => 'Test Template', 'id' => '1', );
$adminuser = 'DemoAdmin';

# Call API
$results = localAPI($command,$values,$adminuser);
if ($results['result']!="success") echo "An Error Occurred: ".$results['result'];

{/php}

 

You would have to use the external API code, it put it in PHP file by itself. The internal API code is made to use within templates, modules, addons, etc.

Edited by SeanP
Link to comment
Share on other sites

Ach, I knew I was missing something obvious. Thanks.

 

However, the code now returns

An Error Occurred: error

 

I remember now that I had done this before, and this is the point I got stuck at. I have changed the username to my actual admin user. What am I doing wrong?

Link to comment
Share on other sites

This usually happens when someone does not have an email template set up. Please go into your admin setup and verify that you have one. If not, create one and try again.

 

If the error persists, you should modify your code to the following:

 

 if ($results['result']!="success") echo "An Error Occurred: ".$results['message'];

 

Then please paste that new error message here.

Link to comment
Share on other sites

  • 10 years later...
On 9/28/2013 at 12:20 AM, shout said:

I know this is a simple question, but I'm having trouble getting started--been struggling through the documentation and searching this community for a while.

 

This page in the documentation says:

 

 

So I know it's possible to use the internal API in a template. However, when I try to do it, it doesn't work. The Internal API example code is PHP, doesn't work in the templates.

 

 

<?php

# Set Vars
$command = 'SendEmail';
$values = array( 'messagename' => 'Test Template', 'id' => '1', );
$adminuser = 'DemoAdmin';

# Call API
$results = localAPI($command,$values,$adminuser);
if ($results['result']!="success") echo "An Error Occurred: ".$results['result'];

?>
 

 

 

Putting that directly in a template just results in it getting commented out. So I created test.php in the root WHMCS folder, put that code in it, and tried calling it from within a template with a form, but I got this error:

 

 

Fatal error: Call to undefined function localAPI() in /path/to/file/test.php on line 9
 

 

 

Where is the demo code for the API supposed to go, and how do I call it??

How do I use the WHMCS Internal API in a template? I would be very happy if you could let me know, thanks. I know this is an old discussion but the answer to my question is very important I am appealing to the admin. Please approve my post, Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated