Weird issue with retrieving template info (PHP API)

97 views
Skip to first unread message

Hiranthi Molhoek-Herlaar

unread,
Feb 18, 2014, 4:33:32 PM2/18/14
to mailchimp-...@googlegroups.com
OK, so.. I'm trying to retrieve the template info for a given template, but for some reason that's very hard.

Whenever I try to fetch the template info the ID is getting set to 1 ór I get an error saying "A backend database error has occurred. Please try again later or report this issue."

I've been in all the steps of the code, echo'd / printed / added to Excetion what the value of the tpl ID was at that point (it's for a plugin, going through some steps before it comes to the Mailchimp API): it's the correct ID.
Then I went into the Mailchimp Templates.php : correct ID. Then I went into Mailchimp.php and check what the value for template_id was right before it was put into json: correct ID.

Then I thought: let's check what it looks like after it's been through json_encode: still the correct ID.


try
{
   
return $this->api->templates->info( $tpl_id );
}
catch ( Mailchimp_Error $e )
{
    throw new Exception( sprintf( __('The template info for ID %d could not be retrieved.','onx-cp'), $tpl_id ) );
}


the first $tpl_id (within try) gives the correct template ID, however, within the catch-part $tpl_id suddenly is 1 (in Mailchimp it's own Exceptions too, I just added it there for troubleshooting purposes).

Colt

unread,
Feb 18, 2014, 5:14:23 PM2/18/14
to mailchimp-...@googlegroups.com
Hey Hiranthi!

We'll be happy to check into everything a bit further but we'll need a bit more information in order to troubleshoot things a bit further.

Could you include any relevant code that is being used to make this call?

Also, if that var is getting lost somewhere in translation before the call, it may be a better bet to reach out to a coding community such as StackOverflow.

If you'd like to keep that code out of the public eye though, you can send an email over to he...@mailchimp.com with ATTN: COLT in the subject line, and I'll be happy to take a further look.

Hiranthi Molhoek-Herlaar

unread,
Feb 19, 2014, 2:09:47 AM2/19/14
to mailchimp-...@googlegroups.com
Honestly: that was about everything, but I'll post a bit more. And like I said: it doesn't get lost before it's getting sent to MailChimp, but somewhere after that. It doesn't get lost in my code anyway, because before the json_encode in the MailChimp PHP API (just before it's sent to MailChimp) the ID is still correct.


Anyway, this is a little more:

class CPAPI
{

public function __construct( $apikey, $options = '' )
{
try
{
require_once( trailingslashit( ONXCP_PLUGIN_DIR ) . 'api/mc/Mailchimp.php' );
$this->api = new Mailchimp( $apikey );
}
catch ( Mailchimp_Error $e )
{
throw new Exception( sprintf( __('The required API file could not be opened.','onx-cp'), $tpl_id ) );
}
} // end __construct


function get_default_template()
{
$settings = get_option( 'option_name' ); // took the actual option name out
return $this->get_template_info( $settings['default-template'] );
} // end get_default_template


function get_template_info( $tpl_id )
{
try
{
return $this->api->templates->info( $tpl_id );
}
catch ( Mailchimp_Error $e )
{
throw new Exception( sprintf( __('The template info for ID %d could not be retrieved.','onx-cp'), $tpl_id ) );
}
} // end get_template_info
}


And this is where I'm requesting the template info:

global $ONX_CP;
$api = new CPAPI( $ONX_CP->key );

$default = $api->get_default_template();



The ID that is getting retrieved in the get_default_template() function is 231454, that ID is good up until (at least) right after the json_encode inside call() in Mailchimp.php (part of the official MailChimp API). So in my own code it constantly is 231454, but when I'm handing it over to the MailChimp API it gets changed to 1, for whatever reason (or I'm getting the backend database error).




Op dinsdag 18 februari 2014 22:33:32 UTC+1 schreef Hiranthi Molhoek-Herlaar:

Hiranthi Molhoek-Herlaar

unread,
Feb 19, 2014, 2:14:51 AM2/19/14
to mailchimp-...@googlegroups.com
Hmm.. just found that I can enable debugging for the API and for some reason there appear to be making multiple calls to the API.

The first response is the template info, right after that I'm seeing this:

[Wed Feb 19 08:11:02 2014] [error] [client] Completed in 598.02ms
[Wed Feb 19 08:11:02 2014] [error] [client] Got response: {"status":"error","code":-91,"name":"PDOException","error":"A backend database error has occurred. Please try again later or report this issue."}

So for some reason it's making a second call and that's the response that's being sent back to my function. 

Hiranthi Molhoek-Herlaar

unread,
Feb 19, 2014, 3:41:53 AM2/19/14
to mailchimp-...@googlegroups.com
Still no idea where the second request was coming from, but I disabled the custom WP apply_filters I had added (for making it possible to add other mailing providers) and approached it a bit differently. No more second request.

Colt

unread,
Feb 19, 2014, 9:42:24 AM2/19/14
to mailchimp-...@googlegroups.com
So without that second request are you now getting the correct data returned?

If you're using WordPress there may be some sort of internal conflict going on that is causing that request to be modified. I made the request and it does appear to be returning the correct data regarding that template. Modifying the wrappers can also lead to unexpected results in some cases, my test case was written using our Simple Wrappers.

require_once 'MailChimp.class.php';
$MailChimp = new MailChimp('xxxxxxxxx');
$rel = $MailChimp->call('templates/list');
$tmp_id = $rel['user'][0]['id'];
$rel = $MailChimp->call('templates/info',array('template_id' => $tmp_id));
print_r($rel);


Reply all
Reply to author
Forward
0 new messages