1.0.1

vCenter Chargeback API Programming Guide
18 VMware, Inc.
}
finally {
if (post != null) {
post.releaseConnection();
}
}
}
}
Ifsuccessful,theAPIreturnsanXMLfilethatindicatesthestatus.
Add a Fixed Cost
Afixedcostisadefinitecostthatcanbechargedonanentity.UsingvCenterChargebackAPI,youcancreate
fixedcostsforentities.
TheURLforthisAPIis<HTTP_request_method> <Base_URL>/fixedCost.Youcandefineacalllike
this:
POST https://123.123.123.123/vCenter-CB/api/fixedCost
TheAPItakesarequestXMLfileinwhichyoucanspecifythefixedcostnameanditsdescription.
The followingisasamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<FixedCosts>
<FixedCost>
<Name>Fixed Cost 1</Name>
<Description>Fixed Cost 1 description</Description>
</FixedCost>
</FixedCosts>
</Request>
ThefollowingisasampleprogramthatcallstheAddanFixedCostAPI.Makesurethatyou:
UpdatetheLogin-request.xmlwithrequiredvaluesandrunthelogin.javasamplecode.
UpdatetheaddFixedCost-request.xmlwithfixedcostnameanditsdescription.
/**
* This method is to add a fixed cost in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleAddFixedCost(String requestFilePath,
String baseURL, String clientVersion) throws IOException,
JDOMException, NoSuchAlgorithmException, KeyManagementException,
HttpException {
PostMethod post = null;
NameValuePair[] parameters = { new NameValuePair("version",
clientVersion) };
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
String bodyString = CommonUtil.xmlAsString(requestDocument);
Protocol.registerProtocol("https", new Protocol("https",
(ProtocolSocketFactory) new FakeSSLCertificateSocketFactory(),
443));
String uri = "https://" + baseURL + "/vCenter-CB/api/fixedCost";