• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Cfhttp Curl

Community Beginner ,
Dec 04, 2015 Dec 04, 2015

Copy link to clipboard

Copied

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.

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Dec 07, 2015 Dec 07, 2015

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 bot

...

Votes

Translate

Translate
Guide ,
Dec 04, 2015 Dec 04, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2015 Dec 06, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 06, 2015 Dec 06, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2015 Dec 06, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 07, 2015 Dec 07, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 07, 2015 Dec 07, 2015

Copy link to clipboard

Copied

LATEST

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! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation