中文论坛 (Forum for Chinese Speakers)

Moderator: yuhesky

#796064
文档里没有具体说明,我用以下方法传入post参数会出错:
Code: Select all
	$variables = json_encode(array(
            "dataTable" => $dataTable,
            "dataId" => $dataId            
        ));
         $postParams = array(
            'pro_uid'    => $processId,
            'tas_uid'    => $firstTaskId,
            'variables'  => $variables 
        );
#796073
amosbatto wrote:What is the rest of your code?
You need to use http_build_query() when sending the variables.
Code: Select all
public function startCase($processId,$firstTaskId,$dataTable,$dataId){
        $user = $this->username;
        $pwd = $this->passward;
        //请求地址从配置获取并组装!!!!!!!
        //$url = "http://localhost:8000/api/1.0/workflow/cases";
        $url =  self::PM_HOST.self::PM_RESTAPI_PATH.self::PM_WORK_SPACE."/cases";
        //传入对应的业务数据
        $variables = json_encode(array(
            "dataTable" => $dataTable,
            "dataId" => $dataId            
        ));
        $postParams = array(
            'pro_uid'    => $processId,
            'tas_uid'    => $firstTaskId,
            'variables'  => $variables
        );
        $oToken = $this->getPMAccessToken($user, $pwd);
        $accessToken =  $oToken->access_token;
        $ret = $this->pmRestRequest("POST",$url,$postParams,$accessToken);
        return $ret;
    
    }
    
Code: Select all
  public function pmRestRequest($method = "GET",$url,$postParams = null,$accessToken){
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$accessToken));
    
        switch ($method){
            case "GET" :
                curl_setopt($ch, CURLOPT_HTTPGET, true);
                break;
            case "POST":
                curl_setopt($ch, CURLOPT_POST,true);
                curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($postParams));
                break;
            case "PUT" :
                curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($postParams));
                break;
            case "PATCH":
                curl_setopt($ch, CULROPT_CUSTOMREQUEST, 'PATCH');
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
                break;
            case "DELETE":
                curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
                curl_setopt($ch, CURLOPT_POSTFIELDS,$postParams);
                break;
        }
    
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $ret = json_decode(curl_exec($ch));
        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        $return = array(
            "httpCode"  => $statusCode,
            "returnValue" => $ret
        );
        return $return;
    }
I have used http_build_query(),but the response still raise error:400 Bad Request: Invalid value specified for `variables`
#796074
Code: Select all
 $postParams = array(
            'pro_uid'    => $processId,
            'tas_uid'    => $firstTaskId,
            'variables'  => $variables
        );
我把这里的参数名variables改成variable,执行成功,生成了新的case,返回值200,但是变量并没有设置成功
Code: Select all
 $postParams = array(
            'pro_uid'    => $processId,
            'tas_uid'    => $firstTaskId,
            'variable'  => $variables
        );
#796083
Don't use json_encode().

You need to use this format to create a new case with variables:
Code: Select all
$processId = '49433188659fd0135827d19009479146';
$taskId = '56257615159fd021fa81349070852612';
$url = "/api/1.0/workflow/cases";

$aParams = array(
  'pro_uid'   => $processId,
  'tas_uid'   => $taskId,
  'variables' => array(array(
    'name'         => 'John Doe',                      //textbox
    'address'      => "636 Main St.\nPlano, TX 34356", //textarea, with \n for line break               
    'country'      => 'MX',                            //dropdown, selected value
    'country_label'=> 'Mexico',                        //dropdown, selected label (optional)
    'hasContract'  => array('1'),                      //checkbox, array('1') to mark, array('0') to unmark
    'selectProduct'=> 'cookies',                       //radiogroup, selected value (not label)
    'selectStates' => array('IN', 'WI'),               //checkgroup, selected values in an array
    'dueDate'      => '2018-11-25 23:59:59',           //datetime, in 'YYYY-MM-DD HH:MM:SS' format
    'orderList'    => array(                           //grid with textbox, checkbox & dropdown
      '1' => array('price'=>23.45, 'inCash'=>'1', 'creditCard'=>'Visa'),
      '2' => array('price'=>56.74, 'inCash'=>'0', 'creditCard'=>'Discover') 
    ) 
    //Note: checkboxes inside grids have values of '1' or '0', not array('1') or array('0') 
    //like checkboxes outside grids
  ))
);                  

$oRet = pmRestRequest("POST", $url, $aParams, $oToken->access_token);

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]