Happy Business Starts Here

Zuora Alumni

billingPreview callout via REST

 

How do I do a "billingPreview" callout via REST?



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

1 REPLY 1
Highlighted
Zuora Alumni

Re: billingPreview callout via REST

Summary

 

There are currently methods to make subscribe/previews, but these are different than the new "billingPreview" API

 

"billingPreview" is not currently available out of the box, and can be made with a custom call out.

 

The following example demonstrates

 

  • using zApi to login with the configured connection credentials
  • using custom object deserialization (not necessary)

 

Code Sample

 

public class InvoiceItem {

    String SubscriptionNumber;
    Double ChargeAmount;
    String Id;
    String ChargeDate;
    String ChargeType;
    String SubscriptionId;
    String RatePlanChargeId;
    String ServiceStartDate;
    String UOM;
    String ServiceEndDate;
    Integer Quantity;
    String ChargeNumber;
    String ProcessingType;

}

public class Account {

    String AccountId;
    List<InvoiceItem> InvoiceItem = new List<InvoiceItem>();

}

public class Response {

    List<Account> results = new List<Account>();

}

Zuora.zApi ZAPI = new Zuora.zApi();

Zuora.zApi.LoginResult login_result = ZAPI.zlogin();

System.debug(login_result.Session);

Http http = new Http();

HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Content-Type','application/json');

req.setEndpoint('https://rest.apisandbox.zuora.com/v1/action/billingPreview"');
req.setBody(
'{'+
'   "requests":[{'+
'       "AssumeRenewal":"Autorenew",'+
'       "IncludingEvergreenSubscription":"true",'+
'       "AccountId":"2c92c0f85cc01d76015cc4bd74e721fd",'+
'       "TargetDate":"2017-07-15"'+
'   }]'+
'}'
);

HttpResponse res = ZAPI.sendRequest(req);

Response results = (Response)System.JSON.deserialize(res.getBody(),Response.class);

System.debug(results);

for(Account a: results.results){
    for(InvoiceItem ii: a.InvoiceItem){
        System.debug('SubscriptionNumber:'+ii.SubscriptionNumber+' ChargeNumber:'+ii.ChargeNumber+' InvoiceItem:'+ii.Id+' ChargeAmount:'+ii.ChargeAmount);
    }
}

 

 

Note About the Object Deserialization

 

Custom objects are not required, and using generic deserialization, a standard Map would be returned.

ex:

 

Map < String, Object > data = (Map < String, Object > ) JSON.deserializeUntyped( resp.getBody() );

 

This was provided as a quick example, and a better approach would be to further customize the deserialization to use the managed package obejcts.

 

 

Additional Reference

 



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √