1

Ampscript code which need to be converted to Soap API in Cloud page :

   %%[
  SET @rr_1=CreateObject("RetrieveRequest")
SetObjectProperty(@rr_1,"ObjectType","Subscriber")
AddObjectArrayItem(@rr_1,"Properties","Status")

SET @sfp=CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp,"Property","SubscriberKey")
SetObjectProperty(@sfp,"SimpleOperator","equals")
AddObjectArrayItem(@sfp,"Value",@sub_key)
SetObjectProperty(@rr_1,"Filter",@sfp)
SET @sub=InvokeRetrieve(@rr_1,@rrStatus, @rrRequestID)
 IF RowCount(@sub) > 0 THEN
  SET @lisStat = Row(@sub,1)
  SET @status = Field(@lisStat,'Status')
  IF @status =='Unsubscribed' THEN 
  SET @unsub_tooltip= 'You have already Unsubscribed'
  ENDIF
  ENDIF
  ]%%

Cloud Page

<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>
 <meta name="description" content="">
 <meta name="viewport" content="width=device-width, initial-scale=1">

%%[

var @subkey
var @callstatus,@response,@payload

set @paylaod=""


set @payload=concat(@payload,'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">')
set @payload=concat(@payload,'<soapenv:Header>')
set @payload=concat(@payload,'<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">')
set @payload=concat(@payload,'<wsse:UsernameToken wsu:Id="UsernameToken-24440876" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">')
set @payload=concat(@payload,'<wsse:Username>USERNAME</wsse:Username>')
set @payload=concat(@payload,'<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>')
set @payload=concat(@payload,'</wsse:UsernameToken>')
set @payload=concat(@payload,'</wsse:Security>')

set @payload=concat(@payload,'</soapenv:Header>')
set @payload=concat(@payload,'<soapenv:Body>')

set @payload=concat(@payload,'<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">')
set @payload=concat(@payload,'<RetrieveRequest>')
set @payload=concat(@payload,'<ObjectType>Subscriber</ObjectType>')

set @payload=concat(@payload,'<Properties>Status</Properties>')
set @payload=concat(@payload,'<Properties>SubscriberKey</Properties>')
set @payload=concat(@payload,'<Filter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="SimpleFilterPart">')
set @payload=concat(@payload,'<Property>SubscriberKey</Property>')
set @payload=concat(@payload,'<SimpleOperator>equals</SimpleOperator>')
set @payload=concat(@payload,'<Value> **Subscriber Key Value ** </Value>')
set @payload=concat(@payload,'</Filter>')

set @payload=concat(@payload,'</RetrieveRequest>')
set @payload=concat(@payload,' </RetrieveRequestMsg>')
set @payload=concat(@payload,'</soapenv:Body>')
set @payload=concat(@payload,'</soapenv:Envelope>')

HTTPPost2('https://mcwvjyt2gp8c5mb-pwn3kk9859p0.soap.marketingcloudapis.com/Service.asmx','text/xml', @payload, false, @callstatus, @response,'SoapACTION','Retrieve')

    SET @sub = BuildRowsetFromXml(@callstatus, "//Status", 1)
    set @rownumber=RowCount(@sub) 
     IF RowCount(@sub) > 0 THEN
    SET @ListStat = Row(@sub, 1)
    SET @status = Field(@ListStat,'Status')

 IF @status =='Unsubscribed' THEN 
  SET @unsub_tooltip= 'You have already Unsubscribed'
  ENDIF
  ENDIF


 ]%%


 Records %%=v(@rownumber)=%%

  <br><br> 

Response from cloud page %%=v(@callstatus)=%%

</head>
<body>
</body>
</html>

OUTPUT of cloudpage :

I am getting zero as the rowcount value when there are two records present in the soap response

Records 0

Response from cloud page RetrieveResponseurn:uuid:f90e3ce9-5d14-45c7-9769-7f18e446fc0furn:uuid:71a2a342-c88b-4aad-932a-923ab771ee49http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous2019-10-31T15:48:01Z2019-10-31T15:53:01ZOK62686bd3-2584-4c00-9dab-7c23cd497e64Subscriber Key Value **ActiveSubscriber Key Value **Unsubscribed

Response of SOAP call from SOAP UI

<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" 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">
   <soap:Header>
      <wsa:Action>RetrieveResponse</wsa:Action>
      <wsa:MessageID>urn:uuid:4fbb8de8-7c66-47a2-9115-2d88873ccb7c</wsa:MessageID>
      <wsa:RelatesTo>urn:uuid:a25103e0-2741-4989-ac42-e0783611485a</wsa:RelatesTo>
      <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
      <wsse:Security>
         <wsu:Timestamp wsu:Id="Timestamp-82bf3a2c-6e57-4070-b38f-b46a8d120eb0">
            <wsu:Created>2019-10-31T15:42:29Z</wsu:Created>
            <wsu:Expires>2019-10-31T15:47:29Z</wsu:Expires>
         </wsu:Timestamp>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <OverallStatus>OK</OverallStatus>
         <RequestID>62565386-13c8-4948-b54f-472564a1043d</RequestID>
         <Results xsi:type="Subscriber">
            <PartnerKey xsi:nil="true"/>
            <ObjectID xsi:nil="true"/>
            <SubscriberKey>**SUB Key Vaule**/SubscriberKey>
            <Status>Active</Status>
         </Results>
           <Results xsi:type="Subscriber">
            <PartnerKey xsi:nil="true"/>
            <ObjectID xsi:nil="true"/>
            <SubscriberKey>**SUB Key Vaule**</SubscriberKey>
            <Status>Unsubscribed</Status>
         </Results>
      </RetrieveResponseMsg>
   </soap:Body>
</soap:Envelope>

1 Answer 1

0

You can use WSProxy, as explained below :

  <script type="javascript" runat="server">
    Platform.Load("core","1.1.5");
    var prox = new Script.Util.WSProxy();
    var cols = ["Status","SubscriberKey"];
    var filter = {
        Property: "SubscriberKey",
        SimpleOperator: "equals",
        Value: "** any SubscriberKey** "
    };
    var data = prox.retrieve("Subscriber", cols, filter);
    var status = data.Results[0].Status;
    Variable.SetValue("@Status",status);
    </script> 

    %%=v(@Status)=%%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .