cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Get all Subscriptions list

Hi,

 

I know Get a List of Subscriptions function only return upto 1000 records and my client needs full list of subscripitons for reporting purpose. 

 

We are storing subscripiton id in our database, i tried "get a subscripiton" function to fetch subscripiton data one by one but this is not good approach and server timeout issues as we have around 2000 subscripitons.

 

Can you please suggest suitable soluiton for this issue. 

 

Thanks

jay71134
Contributor
6 REPLIES 6

Hello @jay71134,

 

You should be able to get your desired records by utilizing the paging limit and offset parameters. You can also use orderBy to get records in specif order. If you can determine how many records your server will get before timing out, you could break your calls into batches.

<sorting>
      <orderBy>id</orderBy>
      <orderDescending>false</orderDescending>
   </sorting>
   <paging>
      <limit>1000</limit>
      <offset>1</offset>
   </paging>
Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor

@NexusSoftware  Thank you for quick response.  I tried pagging with offset but it does not return anything.  I set limit to 1000 and offset 2 so we get 1001 to 2000 records. Any suggestion please.

 

Thanks

When calling ARBGetSubscriptionListRequest, what are you specifying for the searchType?

 

<ARBGetSubscriptionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
   <merchantAuthentication>
      <name>{API-LOGIN}</name>
      <transactionKey>{TRANSACTION-KEY}</transactionKey>
   </merchantAuthentication>
   <refId>123456</refId>
   <searchType>subscriptionActive</searchType>
   <sorting>
      <orderBy>id</orderBy>
      <orderDescending>false</orderDescending>
   </sorting>
   <paging>
      <limit>1000</limit>
      <offset>1</offset>
  </paging>
</ARBGetSubscriptionListRequest>
Powered by NexWebSites.com -
Certified Authorize.net developers

I am also working on this issue; this is being coded in PHP using the following function:

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/anet_php_sdk/vendor/autoload.php';
$testing = 'TRUE';
//$testing = 'FALSE';

function getSubscriptionsList($searchtype, $pagenum, $testing){

	// Common Set Up for API Credentials
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(MERCHANT_TRANSACTION_KEY);

    $refId = 'ref' . time();

    $sorting = new AnetAPI\ARBGetSubscriptionListSortingType();
    $sorting->setOrderDescending(true);
    $sorting->setOrderBy("id");
    
    $paging = new AnetAPI\PagingType();
    $paging->setLimit("1000");
    $paging->setOffset($pagenum);
	if ($testing == 'TRUE') {
	echo "<pre>";
	var_dump($paging);
	echo "</pre>";
		
	}
    $request = new AnetAPI\ARBGetSubscriptionListRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setSearchType($searchtype);
    $request->setSorting($sorting);
    $request->setPaging($paging);

    $controller = new AnetController\ARBGetSubscriptionListController($request);

    $response = $controller->executeWithApiResponse(Envir);

    if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")){
	if ($testing == 'TRUE') {
	echo "<pre>response->getTotalNumInResultSet() is giving: ";
	var_dump($response->getTotalNumInResultSet());
	echo "</pre>";
	if( $testing == 'TRUE')
	{
		echo "<pre>Response:<br/>";
		var_dump($response);
		echo "</pre>";			
	}
		
	}
        //if have subscriptions
        if( $response->getTotalNumInResultSet() >=1 ){

            //$subscriptions = '';
            $subscriptions[] = $response->getSubscriptionDetails();            
        } else{
			//$subscriptions = '';
		}
        return $subscriptions;

     }
    else
    {
        echo "ERROR :  Invalid response\n";
        $errorMessages = $response->getMessages()->getMessage();
        echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
    }

} 

When I run this through a while loop that sets page numbers from 1-4 and using the testing option to dump both the paging object and the Total number in result set I get the following responses:

 

object(net\authorize\api\contract\v1\PagingType)#5 (2) {
  ["limit":"net\authorize\api\contract\v1\PagingType":private]=>
  string(4) "1000"
  ["offset":"net\authorize\api\contract\v1\PagingType":private]=>
  int(1)
}

response->getTotalNumInResultSet() is giving: int(1881)

object(net\authorize\api\contract\v1\PagingType)#182 (2) {
  ["limit":"net\authorize\api\contract\v1\PagingType":private]=>
  string(4) "1000"
  ["offset":"net\authorize\api\contract\v1\PagingType":private]=>
  int(2)
}

response->getTotalNumInResultSet() is giving: int(0)

object(net\authorize\api\contract\v1\PagingType)#3990 (2) {
  ["limit":"net\authorize\api\contract\v1\PagingType":private]=>
  string(4) "1000"
  ["offset":"net\authorize\api\contract\v1\PagingType":private]=>
  int(3)
}

response->getTotalNumInResultSet() is giving: int(0)

object(net\authorize\api\contract\v1\PagingType)#3850 (2) {
  ["limit":"net\authorize\api\contract\v1\PagingType":private]=>
  string(4) "1000"
  ["offset":"net\authorize\api\contract\v1\PagingType":private]=>
  int(4)
}

response->getTotalNumInResultSet() is giving: int(0)

It seems pretty obvious that the entire volume is being returned in the first loop iteration and that the 2nd through 4th iteration is doing nothing at all. What I am wondering is why?

 

Addendum: In test mode the search type is set to "subscriptionActive":

	if( $testing == 'TRUE')
	{
	$sdate	= date( 'Y-m-d', strtotime( "2017-01-01" ) );
	$edate  = date( 'Y-m-d', strtotime( "2017-11-30" ) );
	$searchtype = "subscriptionActive" ;
		
	}

 

 

<ARBGetSubscriptionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
   <merchantAuthentication>
      <name>5KP3u95bQpv</name>
      <transactionKey>346HZ32z3fP4hTG2</transactionKey>
   </merchantAuthentication>
   <refId>123456</refId>
   <searchType>subscriptionActive</searchType>
   <sorting>
      <orderBy>id</orderBy>
      <orderDescending>false</orderDescending>
   </sorting>
   <paging>
      <limit>1000</limit>
      <offset>1</offset>
   </paging>
</ARBGetSubscriptionListRequest>

While trying this API out on the developer reference website: 

 

https://developer.authorize.net/api/reference/index.html#recurring-billing-get-a-list-of-subscriptio...

 

I get the following response

 

<?xml version="1.0" encoding="utf-8"?> 
<ARBGetSubscriptionListResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <refId>
    123456
  </refId>
  <messages>
    <resultCode>
      Ok
    </resultCode>
    <message>
      <code>
        I00001
      </code>
      <text>
        Successful.
      </text>
    </message>
  </messages>
  <totalNumInResultSet>
    11629
  </totalNumInResultSet>
  <subscriptionDetails>
      ....
  </subscriptionDetails>
</ARBGetSubscriptionListResponse>

This indicates that with the offset of 1 and limit of 1000, the result would contain records 1-1000

 

So, the offset of 2 and limit of 1000, the result would contain records 1001-2000.

Similarly, offset 3 limit 1000, -> result records 2001-3000 and so on. The final result set with be with offset 12 limit 1000 -> records 11001 - 11629

 

However all calls having offset greater than 1 have this in the response.

  <totalNumInResultSet>
    0
  </totalNumInResultSet>

 This just means the count is only returned in the first offset API call. But this doesn't mean that you are getting no records in each subsequent offset call. The records are still fetched correctly.

akagarwa
Authorize.Net Developer Authorize.Net Developer
Authorize.Net Developer

Yes, that was absolutely it. Thanks for the helping hand.