Skip to content

Instantly share code, notes, and snippets.

@gerbal
Last active January 14, 2022 11:41
Show Gist options
  • Save gerbal/7b26a244c63f7ef2637aaaf14df4e60a to your computer and use it in GitHub Desktop.
Save gerbal/7b26a244c63f7ef2637aaaf14df4e60a to your computer and use it in GitHub Desktop.
Chargebee Nested Value encoding

I've been working on improving the Elixir package for interacting with the Chargebee API and have encountered some inconsistency in how the different libraries construct POST request parameters

When I try to serialize a nested nested lists, as one would use when creating coupons, the serializers produce differing output depending on the library implementation.

Chargebee-Ruby produces the following

ChargeBee::Util.serialize({item_constraints: [{item_price_ids: ['id1']}]})

=> {"item_price_ids[0]"=>"id1"}

But Chargebee-Typescript produces

Core.encodeParams({item_constraints: [{price_item_ids: ['id1']}]})
// "item_constraints[item_price_ids][0][0]=id1" 

According to Chargebee Engineers the encoding of this parameter should instead be

{ "item_constraints[item_price_ids][0]" => ["id1"] }

If this is the case, then neither the Ruby nor the Typescript libraries are correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment