coldfusioncfccfhttp

creating chttp using header and parameters


I'm trying to create a cfhttp from a curl request. Here is the request:

curl https://url/paymentMethods \
-H "x-API-key: YOUR_X-API-KEY" \
-H "content-type: application/json" \
-d '{
  "merchantAccount": "YOUR_MERCHANT_ACCOUNT",
  "countryCode": "NL",
  "amount": {
    "currency": "EUR",
    "value": 1000
  },
  "channel": "Web"
}'

I create a function to run the cfhttp:

try{
    apiKey = 'myKey';
    requestURL = 'https://url/';
    merchantAccount = 'myAccount';
    amount = {
      'value': 1000,
      'currency': 'USD'  
    };

    cfhttp(method="GET", url="#requestURL#/paymentMethods", result="data"){
        cfhttpparam(name="x-API-key", type="header", value="#apiKey#");
        cfhttpparam(name="content-type", type="header", value="application/json");
        cfhttpparam(name="merchantAccount", type="formfield", value="#merchantAccount#");
        cfhttpparam(name="countryCode", type="formfield", value="US");
        cfhttpparam(name="amount", type="formfield", value="#amount#");
        cfhttpparam(name="channel", type="formfield", value="web");
    }
    data = deserializeJSON(charge.data);
    WriteDump(data);
} catch(any e){
    WriteDump(e);
}

When I run it, I get the error: Attribute validation error for CFHTTPPARAM. The value of the VALUE attribute is invalid. A string value is required.

Am I sending the parameters wrong?

Thanks


Solution

  • You are passing a structure into your cfhttpparam amount. Try value="#serializeJSON( amount )#"