1

我们正在尝试使用 perl 和 json 自动创建用户。我在 PUT 命令上有这个错误:

<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /https://sandbox.rallydev.com/slm/webservice/1.43/user/create.js.</p>
</body></html>
',
                                    '_rc' => '405',

尝试 POST 给了我这个:

<h1>Not Found</h1>
<p>The requested URL /https://sandbox.rallydev.com/slm/webservice/1.43/user/create.js was not found on this server.</p>
</body></html>
',
                                    '_rc' => '404',

是否有使用 perl 创建 Rally 用户的示例?

4

2 回答 2

0

https错误地以/. 去掉它。

于 2013-07-10T20:07:25.577 回答
0

这是 Perl 中的一个基本示例,展示了如何创建 Rally 用户。需要以下 Perl 模块:

  • REST::客户端
  • JSON
  • MIME::Base64

我在 Ubuntu 12.04 上使用 v5.14.2 对此进行了测试。

use strict;
use warnings;

# Needed includes
use REST::Client;
use JSON;

use MIME::Base64;
use URI;
use URI::Split;

# User parameters
# Must be a Rally Subscription Administrator, or a Workspace Administrator
# in a Rally Workspace whose Workspace Admins have been granted user administration
# privileges
my $username='user@company.com';
my $password='topsecret';

# Rally connection parameters
my $base_url="https://rally1.rallydev.com";
my $wsapi_version = "1.43";

# Connect to Rally and create user
# ====================================

my $headers = {
    Accept => 'application/json',
    Authorization => 'Basic ' . encode_base64($username . ':' . $password)    
};

# instantiate REST Client
my $rest_client = REST::Client->new();

# set host
$rest_client->setHost($base_url);

# Formulate POST request to create user
# Note that the a Rally User must have at least one Workspace Permission / Project Permission
# pair. Thus the user will be given User Permissions in the Default Workspace of the
# Subscription or Workspace Administrator whose RallyID is used to run this script.
# The user will receive Viewer-level permissions to the alphabetically
# First project in the Default Workspace of the Rally UserID used to run the script

my $new_rally_user_id = 'user12@company.com';

print "Connecting to Rally and attempting to create user of UserID: \n";
print $new_rally_user_id . "\n\n";

my $wsapi_endpoint = "/slm/webservice/" . $wsapi_version . "/";
my $user_create_endpoint = $wsapi_endpoint . "user/create.js";
my $user_post_body = '{"User": {"UserName": "' . $new_rally_user_id . '", "EmailAddress": "' . $new_rally_user_id . '"}}';

print "POST Body for user creation:\n";
print $user_post_body . "\n\n";

# Attempt Create
$rest_client->POST($user_create_endpoint, $user_post_body, $headers);

# Output JSON Response
print "Create Response:\n\n";
print $rest_client->responseContent();

这是运行脚本的结果:

$ perl rally_create_user.pl 
Connecting to Rally and attempting to create user of UserID: 
user12@company.com

POST Body for user creation:
{"User": {"UserName": "user12@company.com", "EmailAddress": "user12@company.com"}}

Create Response:
{ "CreateResult" : { "Errors" : [  ],
  "Object" : { "Boolean" : null,
      "CUF" : null,
      "CostCenter" : "None",
      "CreationDate" : "2013-07-11T22:49:00.056Z",
      "Date" : null,
      "Department" : "None",
      "Disabled" : false,
      "DisplayName" : null,
      "Editable" : null,
      "EmailAddress" : "user12@company.com",
      "FirstName" : null,
      "LandingPage" : "/dashboard",
      "LastLoginDate" : null,
      "LastName" : null,
      "LastPasswordUpdateDate" : "2013-07-11T22:49:00.056Z",
      "MiddleName" : null,
      "NetworkID" : null,
      "ObjectID" : 12345678913,
      "OfficeLocation" : "None",
      "OnpremLdapUsername" : null,
      "Phone" : null,
      "RevisionHistory" : { "_rallyAPIMajor" : "1",
          "_rallyAPIMinor" : "43",
          "_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/revisionhistory/12345678915.js",
          "_type" : "RevisionHistory"
        },
      "Role" : "None",
      "ShortDisplayName" : null,
      "Specialty" : null,
      "String" : null,
      "Subscription" : { "_rallyAPIMajor" : "1",
          "_rallyAPIMinor" : "43",
          "_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/subscription/12345678914.js",
          "_refObjectName" : "My Subscription",
          "_type" : "Subscription"
        },
      "SubscriptionAdmin" : false,
      "TeamMemberships" : [  ],
      "Text" : null,
      "UserName" : "user12@company.com",
      "UserPermissions" : [ { "_rallyAPIMajor" : "1",
            "_rallyAPIMinor" : "43",
            "_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/workspacepermission/12345678917u12345678918w3.js",
            "_refObjectName" : "My Workspace User",
            "_type" : "WorkspacePermission"
          },
          { "_rallyAPIMajor" : "1",
            "_rallyAPIMinor" : "43",
            "_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/projectpermission/12345678919u12345678920p1.js",
            "_refObjectName" : "A Project",
            "_type" : "ProjectPermission"
          }
        ],
      "UserProfile" : { "_rallyAPIMajor" : "1",
          "_rallyAPIMinor" : "43",
          "_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/userprofile/12345678921.js",
          "_type" : "UserProfile"
        },
      "_CreatedAt" : "just now",
      "_objectVersion" : "2",
      "_rallyAPIMajor" : "1",
      "_rallyAPIMinor" : "43",
      "_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/user/12345678922.js",
      "_refObjectName" : "user12",
      "_type" : "User",
      "yesno" : null
    },
  "Warnings" : [ "API status is Deprecated and will become Not Supported on 2014-Jun-20" ],
  "_rallyAPIMajor" : "1",
  "_rallyAPIMinor" : "43"
于 2013-07-11T22:58:33.817 回答