Knowledge Center

Knowledge Center > Zuora CPQ > Zuora CPQ Development Resources > Order Builder > Order Builder Reference > sendRequest Method

sendRequest Method

Use the sendRequest global method to send REST requests to Zuora. The method takes in an Apex HTTP request, adds the authentication session header using the credentials set up in Connection Settings, and submits the request to Zuora.

The sendRequest method uses the Salesforce native HttpRequest and HttpResponse classes.

Signature

global System.HttpResponse
Zuora.zApi.sendRequest (System.HttpRequest restRequest)

Parameter

The sendRequest takes the following parameter.

Parameter Type Description
restRequest System.HttpRequest The request header and body in the native Salesforce class.

Return Value

The sendRequest method returns the System.HttpResponse Salesforce class. 

Sample Code

The following code queries the Zuora product catalog via the GET Products REST request.

HttpRequest req = new HttpRequest();
req.setEndpoint('https://apisandbox-api.zuora.com/rest/v1/catalog/products');
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Accept', 'application/json');

Zuora.ZApi zApiInstance = new Zuora.ZApi();
HttpResponse resp = zApiInstance.sendRequest(req);
System.debug(resp);
if(resp.getStatusCode() == 200) {
  Map < String, Object > productData = 
    (Map < String, Object > ) JSON.deserializeUntyped( resp.getBody() );
  System.debug(productData);
}

The following code creates a subscription in Zuora via the Post Subscription REST request: 

 req.setEndpoint('https://apisandbox-api.zuora.com/rest/v1/subscriptions');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Accept', 'application/json');

Map < String, Object > subscribe = new Map < String, Object >();
subscribe.put('accountKey', '8a808255575bdae4015817d070cc3ec0');
subscribe.put('termType', 'EVERGREEN');
subscribe.put('contractEffectiveDate', '2016-01-01');
subscribe.put('termStartDate', '2016-01-01');
subscribe.put('invoiceCollect', false);

Map < String, Object > subscribePlan = new Map < String, Object > {
    'productRatePlanId' => '8a808255575bdae4015796d893ac71f1'
};

List< Map < String, Object >> subscribePlans = 
  new List< Map < String, Object > > 
{
  subscribePlan  
};
subscribe.put('subscribeToRatePlans', subscribePlans);

String payload = JSON.serialize(subscribe);
req.setBody(payload);

Zuora.ZApi zApiInstance = new Zuora.ZApi();
HttpResponse resp = zApiInstance.sendRequest(req);
if(resp.getStatusCode() == 200) {
  Map < String, Object > subscribeData = (Map < String, Object > ) JSON.deserializeUntyped( resp.getBody() );
  System.debug(subscribeData);
}
Last modified

Tags

This page has no custom tags.

Classifications

(not set)