2013-07-10 3 views
1

Мы пытаемся автоматизировать создание пользователей с использованием perl и json. У меня есть эта ошибка на команды PUT:пытается автоматизировать создание пользователя Rally с использованием perl и json

<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?

ответ

0

Вот основной пример в Perl, показывающий, как создать пользователя Rally. Требуется следующие Perl модули:

  • Rest :: Client
  • JSON
  • MIME :: Base64

Я проверил это с помощью v5.14.2 на Ubuntu 12.04.

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='[email protected]'; 
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 = '[email protected]'; 

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: 
[email protected] 

POST Body for user creation: 
{"User": {"UserName": "[email protected]", "EmailAddress": "[email protected]"}} 

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" : "[email protected]", 
     "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" : "[email protected]", 
     "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" 
0

Вы ошибаетесь в своей URI и ее схеме https с помощью ссылки /. Убери это.

+0

Спасибо. Я печатаю переменную непосредственно перед командой PUT, в начале нет слэша. Я не знаю, откуда взялась косая черта. – user123456

+0

Затем обновите вопрос своим кодом. – daxim

Смежные вопросы