Page MenuHomePhabricator

Conduit interprets all arguments from curl requests as strings
Closed, ResolvedPublic

Description

curl http://phabricator.something.com/api/harbormaster.createartifact \
  -d api.token=api-some-key\
  -d buildTargetPHID=PHID-HMBT-some-phid \
  -d artifactKey=jenkins.uri \
  -d artifactData[uri]="http://build:8080/job/blah" \
  -d artifactType=uri \
  -d artifactData[name]="Jenkins Build" \
  -d artifactData[ui.external]=1

Complains with

{"result":null,"error_code":"ERR-CONDUIT-CORE","error_info":"Parameter 'ui.external' has invalid type. Expected type 'optional bool', got type 'string'."}

Replacing 1 with true does not solve.

See also this ponder question (Q326) although there is no info in the question that isn't in this task.

Event Timeline

benjumanji added a project: Conduit.
totova added a subscriber: totova.
eadler updated the task description. (Show Details)Feb 29 2016, 3:01 PM

if it helps anyone, the workaround "fix" is to place the following code in the file "src/applications/conduit/parametertype/ConduitBoolParameterType.php "

$value = (boolean) $value;

at about line 9 just before the following piece of code:

if (!is_bool($value)) {

Its a bit of a hack, so I'm not sure how much to trust this workaround for a production instance of Phabricator, but hopefully, it helps someone out there. The issue is (I think) basically related to http://stackoverflow.com/questions/27446946/preserve-data-type-of-post-fields-when-sending-data-using-php-and-curl where PHP converts the curl input as a string.

eadler added a project: Restricted Project.Aug 5 2016, 5:05 PM
avivey added a subscriber: avivey.Aug 10 2016, 12:24 AM

This also happens with integers and epochs:

curl https://secure.phabricator.com/api/maniphest.search -d api.token=XXXX -d constraints[createdStart]=1439192800
throws "Expected epoch timestamp as integer, got something else."

avivey renamed this task from Conduit interprets booleans from curl requests as strings. to Conduit interprets all arguments from curl requests as strings.Aug 10 2016, 12:24 AM

if it helps anyone, the workaround "fix" is to place the following code in the file "src/applications/conduit/parametertype/ConduitBoolParameterType.php "

$value = (boolean) $value;

at about line 9 just before the following piece of code:

if (!is_bool($value)) {

Its a bit of a hack, so I'm not sure how much to trust this workaround for a production instance of Phabricator, but hopefully, it helps someone out there. The issue is (I think) basically related to http://stackoverflow.com/questions/27446946/preserve-data-type-of-post-fields-when-sending-data-using-php-and-curl where PHP converts the curl input as a string.

This workaround did not work for me :(

benjumanji added a comment.EditedSep 1 2016, 9:25 AM
params="                                                                                                                                                                                   
    {                                                                                                                                                                                      
        \"buildTargetPHID\": \"$PHID\",                                                                                                                                                    
        \"artifactKey\": \"jenkins.uri.$PHID\",                                                                                                                                            
        \"artifactType\": \"uri\",                                                                                                                                                         
        \"artifactData\": {                                                                                                                                                                
            \"uri\": \"http://build:8080/job/$JOB_NAME/$BUILD_NUMBER\",                                                                                                                    
            \"name\": \"Jenkins Build\",                                                                                                                                                   
            \"ui.external\": true                                                                                                                                                          
        },                                                                                                                                                                                 
        \"__conduit__\": { \"token\": \"$CONDUIT_API_TOKEN\" }                                                                                                                             
    }"                                                                                                                                                                                     
                                                                                                                                                                                           
curl https://phabricator.example.com/api/harbormaster.createartifact -d params="$params" > /dev/null 2>&1

This is my current workaround, that I got from spying on arc. It's hideous, but it might help someone.