I can connect to the Stripe API using the code
<cfhttp method = "POST" url="https://api.stripe.com/v1/customers">
<cfhttpparam type="header" name="Authorization" value="Bearer sk_test_.......................">
<cfhttpparam type="FormField" name="id" value = "cust_14">
<cfhttpparam type="FormField" name="name" value =#Customer_Name_1#>
......
</cfhttp>```
But I am unable to pass child parameters associated with fields such as "address".
I have tried the code
<CFSET Town_1 = "..."> <CFSET Street_1 = "..."> <CFSET Street_2 = "...">
<CFSET Address_1 = SerializeJSON({city: #Town_1#, line1: #Street_1#, line2: #Street_2#})>
<cfhttpparam type="FormField" name="address" value = '#Address_1#'>
but this fails, and I get an error
"error": {
"message": "Invalid object",
"param": "address",
"type": "invalid_request_error"
}
Thanks in advance for comments.
Stripe's API uses
application/x-www-form-urlencodedfor posting parameters. This means you are not supposed to serialize the parameters to JSON. Instead, you should pass the parameters as individual parameters with their full "path".If you want to send an address with
line1andcountryyou would send each one separately asaddress[line1]="my_value"andaddress[country]="US".If you wanted to do multiple levels you continue the bracket logic such as
shipping[address][country]="US".With your example it would likely look like this: