WSProxy を介した作成

単一アイテムまたは同じ種別の複数のアイテムを 1 回の呼び出しで作成するには、createItem および createBatch 関数を使用します。

  • この両方の関数は、最初のパラメーターとして、実行するアクションの対象となるオブジェクトタイプを使用します。(例: Email、DataExtension)。
  • 2 番目のパラメーターは、作成時にオブジェクトに設定するフィールドと値を表す JS オブジェクトです。バッチ操作の場合、2 番目のパラメーターは、単一アイテムではなくオブジェクトの配列として渡されます。
  • 省略可能な 3 番目のパラメーターには、SOAP CreateOptions オブジェクトを使用して設定する任意のプロパティが含まれます。

例: 単一の DataExtension オブジェクトを作成する 

この例では、ID と Name の 2 つのフィールドを持つ単一の DataExtension オブジェクトを作成します。

1var prox = new Script.Util.WSProxy();
2
3var guid = Platform.Function.GUID();
4var name = "my test de - " + guid;
5
6var de = {
7    Name: name,
8    CustomerKey: guid,
9    Description: "Another DE added via SSJS",
10    Fields: [{
11        FieldType: "Text",
12        Name: "ID",
13        MaxLength: 36,
14        IsPrimaryKey: true,
15        IsNillable: false,
16        IsRequired: true
17    },
18    {
19        FieldType: "Text",
20        Name: "Name",
21        MaxLength: 200
22    }],
23    CategoryID: 101377
24}
25
26var res = prox.createItem("DataExtension", de);

例: 複数の DataExtension オブジェクトを作成する 

この例では、createBatch 関数を使用して、2 つの同様のデータエクステンションを作成します。

1var prox = new Script.Util.WSProxy();
2var guid = Platform.Function.GUID();
3var name = "my test de - 1 - " + guid;
4
5var de1 = {
6    Name: name,
7    CustomerKey: guid,
8    Description: "Another DE added via SSJS",
9    Fields: [{
10        FieldType: "Text",
11        Name: "ID",
12        MaxLength: 36,
13        IsPrimaryKey: true,
14        IsNillable: false,
15        IsRequired: true
16    },
17    {
18        FieldType: "Text",
19        Name: "Name",
20        MaxLength: 200
21    }],
22    CategoryID: 101377
23}
24guid = Platform.Function.GUID();
25name = "my test de - 2 - " + guid;
26
27var de2 = {
28    Name: name,
29    CustomerKey: guid,
30    Description: "Another DE added via SSJS",
31    Fields: [{
32        FieldType: "Text",
33        Name: "ID",
34        MaxLength: 36,
35        IsPrimaryKey: true,
36        IsNillable: false,
37        IsRequired: true
38    },
39    {
40        FieldType: "Text",
41        Name: "Name",
42        MaxLength: 200
43    }],
44    CategoryID: 101377
45}
46var res = prox.createBatch("DataExtension", [ de1, de2 ]);

応答の例 

単一操作とバッチ操作の両方の結果に SOAP CreateResult オブジェクトの 3 つのプロパティ (「Status」、「RequestID」、「Results」) が含まれます。createItem メソッドは 1 つのアイテムを返し、createBatch メソッドは、メソッドに渡された数のアイテムを返します。

1{
2    "Status": "OK",
3    "RequestID": "fb768ddc-6670-4183-8b9d-4f0d5518bb2e",
4    "Results": [...]
5}

例: オートメーションアクティビティを作成する 

この例では、オートメーションアクティビティを作成します。また、この例には WSProxy に対応する「Raw SOAP Wrapper (未加工の SOAP ラッパー)」が含まれます。

1<script runat="server">
2
3/*
4RAW SOAP WRAPPER:
5<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
6   <soapenv:Header>
7      <wsse:Security soapenv:mustUnderstand="1">
8         <wsse:UsernameToken>
9            <wsse:Username>${#Project#username}</wsse:Username>
10            <wsse:Password>${#Project#pw}</wsse:Password>
11         </wsse:UsernameToken>
12      </wsse:Security>
13   </soapenv:Header>
14   <soapenv:Body>
15      <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
16         <Options/>
17         <Objects xsi:type="Automation">
18            <Client>
19               <ID>${#Project#BU}</ID>
20            </Client>
21            <Name>Example Automation</Name>
22            <CustomerKey>ExampleAutomation</CustomerKey>
23            <Description>My Automation Example</Description>
24            <AutomationTasks>
25               <AutomationTask>
26                  <PartnerKey xsi:nil="true"/>
27                  <ObjectID xsi:nil="true"/>
28                  <Name>Task 1</Name>
29                  <Activities>
30                     <Activity>
31                        <PartnerKey xsi:nil="true"/>
32                        <ObjectID>c7ccca24-4567-4317-b8d0-3874d69c130c</ObjectID>
33                        <Name>Query 1</Name>
34                        <ActivityObject xsi:type="QueryDefinition">
35                           <PartnerKey xsi:nil="true"/>
36                           <ObjectID>c7ccca24-4567-4317-b8d0-3874d69c130c</ObjectID>
37                           <CustomerKey>ExampleQueryActivity</CustomerKey>
38                           <Name>Example Query Activity</Name>
39                        </ActivityObject>
40                     </Activity>
41                  </Activities>
42               </AutomationTask>
43            </AutomationTasks>
44            <AutomationType>scheduled</AutomationType>
45         </Objects>
46      </CreateRequest>
47   </soapenv:Body>
48</soapenv:Envelope>
49*/
50
51    /* Initialize the WSProxy Object */
52    var api = new Script.Util.WSProxy();
53
54    /* Set ClientID */
55    api.setClientId({
56        "ID": Platform.Function.AuthenticatedMemberID(),
57        "UserID": Platform.Function.AuthenticatedEmployeeID()
58    });
59
60    /* Build Query Object */
61    var automation = {
62        Name: 'Example Automation',
63        CustomerKey: 'ExampleAutomation',
64        Description: 'My Automation Example',
65        AutomationTasks: [
66            {
67                Name: 'Task 1',
68                Activities: [
69                    {
70                        ObjectID: 'c7ccca24-4567-4317-b8d0-3874d69c130c',
71                        Name: 'Query 1',
72                        ActivityObject: {
73                            "__Type__": "QueryDefinition",
74                            ObjectID: 'c7ccca24-4567-4317-b8d0-3874d69c130c',
75                            Name: 'Example Query Activity',
76                            CustomerKey: 'ExampleQueryActivity'
77                        }
78                    }
79                ]
80            }
81        ],
82        'AutomationType': 'Scheduled'
83    };
84
85    /* Create via API */
86    var res = api.createItem('Automation', automation);
87</script>

例: データ抽出の作成および開始 

現時点では、WSProxy オブジェクトでは更新と実行のみが許可されるため、WSProxy でデータ抽出を直接作成することはできません。更新の対象は最上位オブジェクト (抽出の名前や customerkey など) のみです。

ただし、次の REST エンドポイントを使用してデータ抽出を作成できます。

データ抽出作成のエンドポイント:

1POST /automation/v1/dataextracts
2Host: .rest.marketingcloudapis.com
3Authorization: Bearer
4
5Content-Type: application/json
6
7{
8   "name": "myDataExtract",
9   "key": "myDataExtract",
10   "description": "",
11   "dataExtractTypeId": "",
12   "fileSpec": "myDataExtract.zip",
13   "intervalType": 0,
14   "dataFields": [
15      { "name": "ColumnDelimiter", "type": "string", "value": "," },
16      { "name": "DECustomerKey", "type": "string", "value": "myDataExtension" },
17      { "name": "HasColumnHeaders", "type": "bool", "value": "True" },
18      { "name": "TextQualified", "type": "bool", "value": "True" },
19      { "name": "UsesLineFeed", "type": "bool", "value": "False" }
20   ]
21}

dataExtractTypeId の場合、データエクステンション抽出の ID は bb94a04d-9632-4623-be47-daabc3f588a6 になります。

データ抽出種別 ID のエンドポイント:

1GET /automation/v1/dataextracttypes
2Host: .rest.marketingcloudapis.com
3Authorization: Bearer
4Content-Type: application/json

対象とする DE の識別子を配置する場所も知る必要があります。これは、DECustomerKey オブジェクト内にある dataFields 配列で見つけることができます。「value」プロパティ内で対象 DE の CustomerKey を書き込みます。

以下の例をガイドとして使用して、データ抽出を作成して実行します (WSProxy または REST API を使用して開始できます)。

データ抽出を開始するためのエンドポイント:

1POST /automation/v1/dataextracts//actions/start
2Host: .rest.marketingcloudapis.com
3Authorization: Bearer

抽出を開始するための WSProxy:

1<script runat=server>
2    Platform.Load("Core","1.1.1");
3    var prox = new Script.Util.WSProxy();
4    var action = "Start";
5    var props = {ObjectID: "”}}"};
6    var opts = {};
7    var data = prox.performItem("DataExtractActivity", props, action, opts);
8</script>

抽出を作成したら、ファイル転送を使用して抽出をリポジトリから適切な FTP ディレクトリに移動します。