2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LINE WORKS API 2.0 を PowerShell で叩いてみる (その5 : ユーザーの登録)

Last updated at Posted at 2022-06-17

これまでの記事では、PowerShell を使い、LINE WORKS API 2.0 を呼び出して LINE WORKS の登録済みのユーザー一覧を取得したり、ユーザー写真のアップロードダウンロードをしてみました。

今回は、ユーザーの登録を試してみます。

ユーザーの登録を確認し、リファレンスに従って、ユーザー情報を JSON で記載し、POST リクエストの Body として呼び出します。
JSON 形式で文字列をカリカリ書いても良いですが、PowerShell を使用する場合には HashTable として Object を組み立てて、最期に JSON 形式に変換するのが簡単だと思います。
必須パラメータと、後々の動作確認のために telephone だけを記載すると、以下でユーザーが作成できます。

<# Token を取得して Header を作るところまでは、その 1 の記事参照#>

$postUserURL = "https://www.worksapis.com/v1.0/users"

[HashTable]$User = @{
    domainId        = 12345678
    email           = "newuser@yourcompany"
    userName        = @{
        lastName            = "lastName"
    }
    passwordConfig  = @{
        passwordCreationType    = "ADMIN"
        password                = "Password1!?"
    }
    telephone       = "090-1234-5678"
}

$response =Invoke-RestMethod -Method POST -Uri $postUserURL -Headers $Header -body (ConvertTo-Json  $User)

作成されたユーザーは $response に入っており、こんな感じで確認できます。
LINE WORKS API 2.0 では、値の入っていないプロパティも返してくれます。

>$response
domainId                  : 12345678
userExternalKey           : 
email                     : newuser@yourcompany
userName                  : @{lastName=lastName; firstName=; phoneticLastName=; phoneticFirstName=}
i18nNames                 : {}
nickName                  : 
privateEmail              : 
aliasEmails               : {}
employmentTypeId          : 
searchable                : True
organizations             : {@{domainId=12345678; primary=True; userExternalKey=; email=newuser@yourcompany; levelId=; executive=False; orgUnits=System.Object[]; organizationName=あなたの会社の名前; levelExternalKey=; levelName=}}
telephone                 : 090-1234-5678
cellPhone                 : 
fax                       : 
location                  : 
task                      : 
messenger                 : 
birthdayCalendarType      : 
birthday                  : 
hiredDate                 : 
locale                    : ja_JP
timeZone                  : Asia/Tokyo
customFields              : {}
relations                 : {}
userId                    : 483ea9b2-1977-4ed9-1593-041c9000c16b
isAdministrator           : False
isPending                 : True
isSuspended               : False
leaveOfAbsence            : @{startTime=; endTime=; isLeaveOfAbsence=False}
isDeleted                 : False
suspendedReason           : 
employmentTypeExternalKey : 
employmentTypeName        : 

または、ConertTo-Json を使えば、JSON 形式で確認することもできます。ConertTo-Json は、階層が深くなると正しく表示してくれないので、-depth を指定しておきます。
JSON 形式でリクエスト ボティを手書きする場合にはこちらも参考になります。

> $response  | ConvertTo-Json -Depth 10
{
  "domainId": 12345678,
  "userExternalKey": null,
  "email": "newuser@yourcompany",
  "userName": {
    "lastName": "lastName",
    "firstName": "",
    "phoneticLastName": "",
    "phoneticFirstName": ""
  },
  "i18nNames": [],
  "nickName": null,
  "privateEmail": null,
  "aliasEmails": [],
  "employmentTypeId": null,
  "searchable": true,
  "organizations": [
    {
      "domainId": 12345678,
      "primary": true,
      "userExternalKey": null,
      "email": "newuser@yourcompany",
      "levelId": null,
      "executive": false,
      "orgUnits": [],
      "organizationName": "あなたの会社の名前",
      "levelExternalKey": null,
      "levelName": null
    }
  ],
  "telephone": "090-1234-5678",
  "cellPhone": null,
  "fax": null,
  "location": null,
  "task": null,
  "messenger": null,
  "birthdayCalendarType": null,
  "birthday": null,
  "hiredDate": null,
  "locale": "ja_JP",
  "timeZone": "Asia/Tokyo",
  "customFields": [],
  "relations": [],
  "userId": "483ea9b2-1977-4ed9-1593-041c9000c16b",
  "isAdministrator": false,
  "isPending": true,
  "isSuspended": false,
  "leaveOfAbsence": {
    "startTime": null,
    "endTime": null,
    "isLeaveOfAbsence": false
  },
  "isDeleted": false,
  "suspendedReason": null,
  "employmentTypeExternalKey": null,
  "employmentTypeName": null
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?