-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove L3_L4 cats.ps1
85 lines (77 loc) · 3.79 KB
/
remove L3_L4 cats.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#define some globals. need some arrays for later, api headers can be changed per environment
$testmode = 0 #make this 0 to actually peform the node unlink call. anything else will just write the call to screen
$L2Array = @()
$L3Array = @()
$results = @()
$headers = @{
"Accept" = "application/json";
"X-inRiver-APIKey" = "" #Insert API KEY
}
$ChannelID = "113323" #insert the channel ID from inriver
$GetStructureURI = "https://apiuse.productmarketingcloud.com/api/v1.0.0/channels/$ChannelID/nodes"
#Invoke-RestMethod -Method:Get -Headers $headers -URI $GetStructureURI
$response = Invoke-RestMethod -Method:Get -Headers $headers -URI $GetStructureURI
#replace $responseSplitTest with $response to actually do the full list of nodes..
#the second part of the and should be removed for the full catalog. else it can be run for individual L1's by putting the L1 sys ID in
foreach($i in $response) {
$channelID,$L1,$L2,$L3,$L4 = $i.Split('/')
#if((!$L3 -eq "") -and ($L1 -eq "114148") ) {
if(!$L3 -eq "") {
$L3Array += $L3
}
#if((!$L2 -eq "") -and ($L1 -eq "114148")) {
if(!$L2 -eq "") {
$L2Array += $L2
}
};
$L3Array = $L3Array | Select-Object -Unique
$L2Array = $L2Array | Select-Object -Unique
write-host "removing links between L2's and L3's"
foreach($L3 in $L3Array){
if(!$L3 -eq "") {
#We have an L3 that needs to be unlinked. get the link ID of the link to it's parent
$GetNodeLinkIDURI = "https://apiuse.productmarketingcloud.com/api/v1.0.0/entities/$L3/links?linkDirection=inbound&linkTypeId=ChannelNodeChannelNodes"
try {
$NodeLinkID = (Invoke-RestMethod -Method:Get -Headers $headers -URI $GetNodeLinkIDURI).id
$DeleteLinkURI = "https://apiuse.productmarketingcloud.com/api/v1.0.0/links/$NodeLinkID"
if($testmode -eq 0) {
write-host "Removing link $NodeLinkID. Calling $DeleteLinkURI..."
Invoke-RestMethod -Method:Delete -Headers $headers -URI $DeleteLinkURI
}
else {
write-host "In test mode, we write this call to screen instead of actually calling the delete.. Call endpoint $DeleteLinkURI"
}
}
catch {
<#Do this if a terminating exception happens#>
}
}
};
Write-Host "Links all removed. now get all of the L2's and create the CSV for the node link rules"
#get the name of each of these, we currently just have the ID
foreach($L2 in $L2Array){
$NodeIDURI = "https://apiuse.productmarketingcloud.com/api/v1.0.0/entities/$L2/summary/fields?fieldTypeIds=ChannelNodeID"
$NodeID = (Invoke-RestMethod -Method:Get -Headers $headers -URI $NodeIDURI).value
$csvoutput = @{
ChannelNodeUniqueValue = $NodeID
Field = "ProductCat2"
value = $NodeID.replace("PM-", "")
}
$results += New-Object PSObject -Property $csvoutput
}
$datetime = Get-date -Format MMddyyyyHHmmss
$csvoutputpath = "C:\Users\getch\Luminos Labs\Luminos Labs - Clients\NDC\Client Shared - NDC\inRiver\Import Files\Model Import Files\NodeLinkRules_$datetime.csv"
$results | Select-Object ChannelNodeUniqueValue, Field, @{label = "Equals";expression={$_.value}} | Export-Csv -Path $csvoutputpath -NoTypeInformation
#$csvoutputpath = "C:\Users\getch\Luminos Labs\Luminos Labs - Clients\NDC\Client Shared - NDC\inRiver\Import Files\Model Import Files\NodeLinkRules_09062022152122.csv"
#call the improt routines to load the link rules that we exported to csv.
#Insert email and pass for the environment below.
& C:\LLInRiverToolkit\ImportToolkit\LL.InRiver.ImportToolkits.exe addlinkdefinitions `
-c "Preferred Medical" `
-u "ChannelNodeID" `
-l "ChannelNodeProducts" `
-i $csvoutputpath `
-r `
-e test `
--user "" `
--pass "" `
--url https://remoting.productmarketingcloud.com