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.
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
...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.
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"}}"/>
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.
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.
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.
Copy link to clipboard
Copied
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!