Skip to main content
Inspiring
December 4, 2015
Answered

Cfhttp Curl

  • December 4, 2015
  • 2 replies
  • 1891 views

Hello,

Box.com has an API that allows files/folders to be manipulated programmatically.  The syntax using the curl command to generate a link to a file uploaded to box.com is:

curl https://api.box.com/2.0/folders/FOLDER_ID -H "Authorization: Bearer ACCESS_TOKEN" --data '{"shared_link": {"access": "open"}}' -X PUT

I'm unable to figure out the correct syntax for sending the --data part of the curl command.  So far, I have this:

    <cfhttp method="PUT" url="#web_svc#"  redirect="yes" timeout="30">

        <cfhttpparam type="header" name="Authorization" value="Bearer #access_token#"/>

        <cfhttpparam type="formField" name="shared_link" encoded="no" value="{"access": "open"}"/>

    </cfhttp>

But Box throws an error:

Invalid value '0={"shared_link": {"access": "open"}}'. Entity body should be a correctly nested resource attribute name/value pair

Any suggestions would be greatly appreciated.

    This topic has been closed for replies.
    Correct answer allen800

    Yes, that was a typo on my part.  I tried to strip the code down to the base issue but obviously failed.  It should've been:

        <cfhttp method="PUT" url="#web_svc#"  redirect="yes" timeout="30">

            <cfhttpparam type="header" name="Authorization" value="Bearer #access_token#"/>

            <cfhttpparam type="formField" name="shared_link" encoded="no" value='{"access": "open"}'/>

        </cfhttp>

    I will try the suggestions and report back.  Both your responses are greatly appreciated.  Thanks much.


    In case anyone else needs to do this, the code below works:

        <cfhttp method="PUT" url="#web_svc#" redirect="yes" timeout="30">

            <cfhttpparam type="header" name="Authorization" value="Bearer #access_token#"/>

            <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />

            <cfhttpparam type="body" encoded="no" value='{"shared_link": {"access": "open"}}'/>

        </cfhttp>

    A million thanks to BKBK and Carl for pointing me in the right direction.  You both rock! 

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 6, 2015

    What about something along these lines

    <cfhttpparam type="header" name="Accept" value="application/json"/>

    <cfhttpparam type="header" name="Content-Type" value="application/json"/>

    <cfhttpparam type="formField" name="data" encoded="no" value="{"shared_link": {"access": "open"}}"/>

    Carl Von Stetten
    Legend
    December 6, 2015

    BKBK‌ - That might work, but I think the issue is really the double quotes within the value attribute. I don't think it is being parsed correctly.

    BKBK
    Community Expert
    Community Expert
    December 6, 2015

    You're right, Carl. It has a typo. The value in the last line should be '{"shared_link": {"access": "open"}}'. I meant it as an additional suggestion.

    Carl Von Stetten
    Legend
    December 5, 2015

    I can think of a few things to try.  First, try using single quotes instead of double quotes to build your key/value statement in the value attribute.  Second, try using single quotes instead of double quotes to define all of the attribute values within the <cfhttpparam> tag, so that the double quotes inside the value attribute are respected. Third, try escaping the quotes within the value attribute by using two double quotes together.  So:

    <cfhttpparam type="formField" name="shared_link" encoded="no": value="{'access': 'open'}'/>

    or

    <cfhttpparam type='formField' name='shared_link' encoded='no' value='{"access": "open"}'/>

    or

    <cfhttpparam type="formField" name="shared_link" encoded="no": value="{""access"": ""open""}'/>

    HTH,

    -Carl V.