本記事は Marketing Cloud Engagement で API 連携のインストール済みパッケージでのアクセストークンの最終リクエスト日時を一覧化する方法について記載します。
ログインアクティビティの監査が必要な Enterprise Business Unit に、以下の構成でデータエクステンション(DE)を作成してください。
名前: AppUser_LoginAudit
外部キー: AppUser_LoginAudit
| 項目名 | データの種別 | 長さ | プライマリキー | Null 可能 | デフォルト値 |
| UserID | テキスト | 100 | チェックなし | チェックなし | |
| UserName | テキスト | 255 | チェックなし | チェックなし | |
| LastLogin | テキスト | 100 | チェックなし | チェックあり | |
| AuditDate | 日付 | チェックなし | チェックなし | 現在のシステム日付の利用 |
注意 1: これにはすべての内部「App」ユーザーが含まれます。これらのユーザーは、インストール済みパッケージの画面には表示されず、編集もできません。
注意 2:DE 保存後、必ず想定通りに DE の設定がされているかご確認ください。AuditDate のデフォルト値の設定が正常にされていない場合、スクリプト実行後、DE にレコードが格納されません。
技術的な注意: 「LastLogin」をNull 可能のテキスト型に設定しているのは、一度もログインしていない場合に API が日付を返さないためです。また、SOAP の日付文字列は、テキストとして記録し、後で変換する方が処理が容易です。
DEの作成後、AccountUser オブジェクトを照会するためのSSJSアクティビティを作成します。インストール済パッケージによって作成されるユーザーは、 Name が「"パッケージ名" app user」となります。このスクリプトは WSProxy を利用して Name に「app user」を含むユーザーを取得し、その ID、Name、および LastSuccessfulLogin(アクセストークンリクエスト日時)を DE に挿入します。
<script runat="server">
Platform.Load("Core", "1.1.1");
try {
var targetDEKey = "AppUser_LoginAudit";
var prox = new Script.Util.WSProxy();
// 1. Define the columns to retrieve from the SOAP object
var cols = ["ID", "Name", "LastSuccessfulLogin"];
// 2. Define the filter (Name contains 'app user')
var filter = {
Property: "Name",
SimpleOperator: "like",
Value: "app user"
};
var moreData = true;
var reqID = null;
var insertedCount = 0;
// 3. Loop through the AccountUser records
while (moreData) {
moreData = false;
// Use getNextBatch if paginating, otherwise retrieve the first batch
var res = reqID == null ? prox.retrieve("AccountUser", cols, filter) : prox.getNextBatch("AccountUser", reqID);
if (res != null && res.Status == "OK") {
// 4. Process the results and insert into the DE
for (var i = 0; i < res.Results.length; i++) {
var user = res.Results[i];
var userId = String(user.ID);
var userName = user.Name || "Unknown";
var lastLogin = user.LastSuccessfulLogin || "Never Logged In";
var insertProps = [
{ Name: "UserID", Value: userId },
{ Name: "UserName", Value: userName },
{ Name: "LastLogin", Value: lastLogin }
];
var insertResult = prox.createItem("DataExtensionObject", {
CustomerKey: targetDEKey,
Properties: insertProps
});
if (insertResult.Status == "OK") {
insertedCount++;
}
}
// 5. Check if there are more rows to fetch
if (res.HasMoreRows) {
moreData = true;
reqID = res.RequestID;
}
}
}
Write("Audit complete. Successfully logged " + insertedCount + " users to the Data Extension.");
} catch (error) {
Write("Error: " + Stringify(error));
}
</script>SSJSアクティビティを実行して AccountUser オブジェクトを照会し、該当するユーザーのログイン詳細を AppUser_LoginAudit DEに記録します。このスクリプトには、WSProxyの getNextBatch によるページネーション機能が含まれています。ユーザーが数千人いる場合でも、2500件ずつのバッチで安全に処理を繰り返します。
005317493

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.