Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created July 12, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/3e6d7cfb8df6cce4043dbe5b61f2b156 to your computer and use it in GitHub Desktop.
Save gitfvb/3e6d7cfb8df6cce4043dbe5b61f2b156 to your computer and use it in GitHub Desktop.
EpiServer Campaign SOAP calls via PowerShell
<#
https://world.episerver.com/documentation/developer-guides/campaign/SOAP-API/introduction-to-the-soap-api/webservice-overview/
WSDL: https://api.campaign.episerver.net/soap11/RpcSession?wsdl
#>
#---------------------------
# SETTINGS
#---------------------------
$mandant = 12345
$user = "api.xxx"
$pass = "password"
#---------------------------
# SESSION
#---------------------------
$soapEnvelopeXml = "<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<login>
<in0>$( $mandant )</in0>
<in1>$( $user )</in1>
<in2>$( $pass )</in2>
</login>
</soap:Body>
</soap:Envelope>"
$header = @{
"SOAPACTION" = "login"
}
$contentType = "text/xml;charset=""utf-8"""
$response = Invoke-RestMethod -Uri "https://api.campaign.episerver.net/soap11/RpcSession" -ContentType $contentType -Method Post -Verbose -Body $soapEnvelopeXml -Headers $header
$sessionId = $response.Envelope.Body.loginResponse.loginReturn.'#text'
#---------------------------
# MAILINGs
#---------------------------
$soapEnvelopeXml = "<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<getIdsInStatus>
<in0>$( $sessionId )</in0>
<in1>campaign</in1>
<in2>ACTIVATION_REQUIRED</in2>
</getIdsInStatus>
</soap:Body>
</soap:Envelope>"
$header = @{
"SOAPACTION" = "getIdsInStatus"
}
$contentType = "text/xml;charset=""utf-8"""
$response = Invoke-RestMethod -Uri "https://api.campaign.episerver.net/soap11/RpcMailing" -ContentType $contentType -Method Post -Verbose -Body $soapEnvelopeXml -Headers $header
$smartCampaigns = $response.Envelope.Body.multiRef.'#text'
#---------------------------
# LOGOUT
#---------------------------
$soapEnvelopeXml = "<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<logout>
<in0>$( $sessionId )</in0>
</logout>
</soap:Body>
</soap:Envelope>"
$header = @{
"SOAPACTION" = "logout"
}
$contentType = "text/xml;charset=""utf-8"""
$response = Invoke-RestMethod -Uri "https://api.campaign.episerver.net/soap11/RpcSession" -ContentType $contentType -Method Post -Verbose -Body $soapEnvelopeXml -Headers $header
$response.Envelope.Body.logoutResponse
<#
https://world.episerver.com/documentation/developer-guides/campaign/SOAP-API/introduction-to-the-soap-api/webservice-overview/
WSDL: https://api.campaign.episerver.net/soap11/RpcSession?wsdl
#>
#---------------------------
# SETTINGS
#---------------------------
$mandant = 12345
$user = "api.xxx"
$pass = "password"
#---------------------------
# SESSION
#---------------------------
$wsdlSession = "https://api.campaign.episerver.net/soap11/RpcSession?wsdl"
$epiSession = New-WebServiceProxy -Uri $wsdlSession #-Namespace WebServiceProxy
$sessionId = $epiSession.login($mandant,$user,$pass)
$sessionId
#---------------------------
# MAILINGs
#---------------------------
$wsdlMailings = "http://api.campaign.episerver.net/soap11/RpcMailing?wsdl"
$epiMailings = New-WebServiceProxy -Uri $wsdlMailings
$campaigns = $epiMailings.getIdsInStatus($sessionId, "campaign", "ACTIVATION_REQUIRED")
$campaigns
$regular = $epiMailings.getIdsInStatus($sessionId, "regular", "DONE")
$regular
#---------------------------
# LOGOUT
#---------------------------
$epiSession.logout($sessionId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment