6 Replies Latest reply on Dec 7, 2015 2:09 PM by allen800

    Cfhttp Curl

    allen800 Level 1

      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.

        • 1. Re: Cfhttp Curl
          Carl Von Stetten Adobe Community Professional & MVP

          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.

          1 person found this helpful
          • 2. Re: Cfhttp Curl
            BKBK Adobe Community Professional & MVP

            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"}}"/>

            1 person found this helpful
            • 3. Re: Cfhttp Curl
              Carl Von Stetten Adobe Community Professional & MVP

              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.

              • 4. Re: Cfhttp Curl
                BKBK Adobe Community Professional & MVP

                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.

                1 person found this helpful
                • 5. Re: Cfhttp Curl
                  allen800 Level 1

                  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.

                  • 6. Re: Cfhttp Curl
                    allen800 Level 1

                    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!