The Infusionsoft API makes it possible to place orders and charge credit cards without your customer ever visiting a single Infusionsoft page. To do this, you’ll need to know your merchant account ID. Infusionsoft doesn’t provide a way to get this via the API. You can get it through your Infusionsoft app, but this involves clicking through to the right screen and then dissecting a page’s URL.
An easier solution, especially if you are building software for clients, is to try to find this information by looking at recent transactions. By looking at recent transactions in the CCharge table, you can find the merchant account ID with a fairly high level of confidence. It is still a good idea to confirm your merchant account ID by looking in Infusionsoft but this helps you know you are looking in the right place.
This code assumes you are using the free Novak Solutions Infusionsoft PHP SDK and you have a config.php with your app name and API key.
<?php // Include the SDK require_once('Infusionsoft/infusionsoft.php'); // Query for recently used merchant IDs $charges = Infusionsoft_DataService::queryWithOrderBy(new Infusionsoft_CCharge(), array('Id' => '%'), 'Id', false, 100, 0, array('MerchantId')); // Loop through $m = array(); foreach($charges as $charge) { if(!isset($m[$charge->MerchantId])) { $m[$charge->MerchantId] = 1; } else { $m[$charge->MerchantId]++; } } if(!empty($m)){ // Find the most used merchant ID $max = array_keys($m, max($m)); $merchantId = $max[0]; } else { $merchantId = false; } // $merchantId = the most used merchant ID from the most recent 100 transactions
We use this code in the free Infusionsoft One-click Upsell plugin for WordPress to make it easier to find your merchant account ID. We hope you find it useful in your own projects!