我无法通过php代码
在rest api中添加grouplist<?php
// Input your info here:
$email = "********* "; // your account email
$password = "*****"; // your account password
$integratorKey = "********"; // your account integrator key, found on (Preferences -> API page)
$accountID = "********** ";
$debug = $_POST["debug"];
$debug = $_POST["debug"];
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling logon webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
if ($debug){
echo "<BR>accountId = " . $accountId . "<BR>baseUrl = " . $baseUrl . "<BR>";
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - status retrieval using filters
/////////////////////////////////////////////////////////////////////////////////////////////////
echo "<BR>Sending new user update...<BR>";
$curl = curl_init($baseUrl . "/users");
if ($debug){
echo "URL is: " . $baseUrl . "/users" . "<BR>";
echo "Title: " . $_POST["title"]."<BR>";
echo "First Name: " . $_POST["firstName"]."<BR>";
echo "Middle Name: " .$_POST["middleName"]."<BR>";
echo "Last Name: " . $_POST["lastName"]."<BR>";
echo "User Name: " .$_POST["userName"]."<BR>";
echo "Password :" . $_POST["password"]."<BR>";
echo "Email: " .$_POST["email"]."<BR>";
echo "Check box:".$_POST['check_list']."<BR>";
}
$data = array("newUsers" => array
(
array
(
"lastName" => $_POST["lastName"],
"firstName" => $_POST["firstName"],
"password" => $_POST["password"],
"userName" => $_POST["userName"],
"email" => $_POST["email"],
"middleName" => $_POST["middleName"],
"title" => $_POST["title"],
"userSettings" => array
(
array
(
"name" => "canSendEnvelope",
"value" => "true"
)
),
"forgottenPasswordInfo" => array
(
"forgottenPasswordQuestion1" => $_POST["forgottenPasswordQuestion1"],
"forgottenPasswordAnswer1" => $_POST["forgottenPasswordAnswer1"]
),
"groupList" => array
(
"groupId" => $_POST["check_list"],
"groupName" => $_POST["check_list"],
"permissionProfileId" => $_POST["check_list"],
"groupType" => $_POST["check_list"]
)
)
)
);
$data_string = json_encode($data);
if ($debug) {
echo "<BR><BR>";
echo $data_string;
echo "<BR><BR>";
}
// build web request
$request_header = array(
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
"X-DocuSign-Authentication: $header" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $request_header);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
//execute web request
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "<BR>error text is --> ";
print_r($json_response); echo "<BR>";
exit(-1);
}
$response = json_decode($json_response, true);
//--- display results
if ($debug){
echo "Received " . $response . " end<BR>";
}
echo "New user created."
?>
答案 0 :(得分:0)
由于groupList
是数组属性,因此您需要单独指定每个组节点。 PHP代码生成的JSON应如下所示:
"groupList": [
{
"groupId": "sample string 1",
"groupName": "sample string 2",
"permissionProfileId": "sample string 3",
"groupType": "sample string 4"
}
],