Passing custom fields to the Create a Subscription API and accessing them in the API response using .NET

Modified on: Sat, 7 Nov, 2015 at 12:53 AM

Custom fields right now are available only for the Customer object. If you would like to retrieve the custom field data, you can use the Retrieve a Customer API. The API response will contain the custom fields, if it is present for that Customer.


Sample Code:


Create Subscription API:

  

EntityResult result = Subscription.Create ()
 .PlanId ("basic")
 .CustomerEmail ("john@user.com")
 .CustomerFirstName ("John")
 .CustomerLastName ("Doe")
 .Param("customer[cf_client_id]", "xyz")
 .Request();

   

The custom field values can be sent using param method with "customer[cf_<attribute_name>]".


Retrieve Custom field value if present in API response:


Customer customer = Customer.Retrieve("<customer_id>").Request().Customer;
Console.WriteLine (customer.GetValue<String> ("cf_client_id", false));

 


The custom field value can be accessed using GetValue<String> ("cf_client_id", false) method. Here, false parameter specifies not to throw error if the API response does not have the custom field value. By default, if the boolean parameter is not sent it will be considered as 'true'.


For other languages, please refer here: https://www.chargebee.com/tutorials/custom-fields-recurring-billing-example.html.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.
×