1

Hi I am trying create a custom unsubscribe page to unsubscribe from a publication list. Below is the code:

 %%[

 VAR  @email, @err, @clientID
 SET @MID = "64*****"

 SET @clientID = CreateObject("ClientID")
 SetObjectProperty(@clientID, "ID", @MID)
 SET @err = 0
 SET @email = Base64Decode(RequestParameter('u'))
 OutputLine(Concat(@email,' is a success 1!'))
 if  IsEmailAddress(@email) then
 OutputLine(Concat(@email,' is a success 2!'))
 //CHECK STATUS IN THE LIST

 var @ListSubObj, @rr, @sfp1, @sfp2, @cfp

 set @rr = CreateObject("RetrieveRequest")
 SetObjectProperty(@rr,"ObjectType","ListSubscriber")
 AddObjectArrayItem(@rr,"Properties","ListID")
 AddObjectAttayItem(@rr,"Properties","Status")

 set @sfp1 = CreateObject("SimpleFilterPart")
 SetObjectProperty(@sfp1,"Property","SubscriberKey") 
 SetObjectProperty(@sfp1,"SimpleOperator","equals")
 AddObjectArrayItem(@sfp1,"Value",@email)

set @sfp2 = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp2,"Property","ListID")
SetObjectProperty(@sfp2,"SimpleOperator","equals")
AddObjectArrayItem(@sfp2,"Value","21735")

set @cfp = CreateObject("ComplexFilterPart")
SetObjectProperty(@cfp,"LeftOperand", @sfp1)
SetObjectProperty(@cfp,"LogicalOperator", "AND")
SetObjectProperty(@cfp,"RightOperand", @sfp2)

SetObjectProperty(@rr,"Filter",@cfp)
 OutputLine(Concat(@rr,'@rr'))
OutputLine(Concat(@cfp,'@cfp'))

   set @ListSubObj = InvokeRetrieve(@rr,@rrStatus,@rrRequestID)
   OutputLine(Concat(rowCount(@ListSubObj),' @ListSubObj'))
   OutputLine(Concat(@ListSubObj,' @ListSubObj'))

if rowCount(@ListSubObj) > 0 then
    var @row
    set @row = row(@ListSubObj, 1)
    set @status = field(@row,'Status')
    if @status != "Active" then
        //USER HAVE ALREADY UNBSUBSCRIBED OR NEVER CONFIRMED
        SET @err = 2
    else
        //SET USER STATUS TO UNSUBSCRIBED IN THE LIST
        VAR @ts_sub
        SET @ts_sub = CreateObject("Subscriber")
        SetObjectProperty(@ts_sub, "EmailAddress", @email)
        SetObjectProperty(@ts_sub, "SubscriberKey", @email)
        AddObjectArrayItem(@ts_sub, "ClientIDs", @clientID) 
        // GET THE LIST
        SET @List = CreateObject("SubscriberList")
        SetObjectProperty(@List, "ID", "21735")
        SetObjectProperty(@List, "Status", "Unsubscribed")
        AddObjectArrayItem(@List, "ClientIDs", @clientID) 

        // ADD THE LIST TO CONTACT
        AddObjectArrayItem( @ts_sub, "Lists", @List )
        // UPDATE THE CONTACT
        InvokeUpdate(@ts_sub)
        SET @err = 0
    endif
else 
OutputLine(Concat(@email,' is a error 1!'))
    SET @err = 1
endif

else
OutputLine(Concat(@email,' is a error 1.2!'))
SET @err = 1
endif 

]%%

I am getting an error: 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.

4
  • 1
    Welcome to SFSE! Please take the tour and read How to Ask. I've taken care of formatting your ampscript for you but, for the future, keep in mind that being consistent with your indentation is pretty important for making it easier for other people to understand your code. I'm not familiar with the marketing cloud, nor ampscript, but is that the entirety of the error you got? If there's more to the error, you should include the entire error message. It might not make sense to you, but it can help the more experienced eyes here narrow down the issue. You should add information by making an edit. – Derek F Mar 6 '19 at 12:16
  • I see a @clientID variable declared and being passed to a pair of AddObjectArrayItem functions, but I don't see it being assigned a value anywhere at the moment—is this the most recent version of the code? – Mark G Mar 6 '19 at 16:38
  • @DerekF :) Thank you for the help and the points which you mentioned. I'll keep these in mind for future. – Yashasvi Pandey Mar 6 '19 at 19:40
  • Hi @Mark I have updated the code now – Yashasvi Pandey Mar 6 '19 at 20:22
3

After trying several tests, I've come to a solution by using the RetrieveRequest object, Filters, and InvokeRetrieve functions. See the code below:

 %%[
  VAR  @email, @err, @clientID
  SET @MID = "Your Account MID"
  SET @clientID = CreateObject("ClientID")
  SetObjectProperty(@clientID, "ID", @MID)
  SET @err = 0
  SET @email = Base64Decode(RequestParameter('u'))
   //OutputLine(Concat(@email,' is a success 1!'))
       if  IsEmailAddress(@email) then
       //CHECK STATUS IN THE LIST
  var @ListSubObj, @rr, @sfp1, @sfp2, @cfp

  set @rr = CreateObject("RetrieveRequest")
  SetObjectProperty(@rr,"ObjectType","ListSubscriber")
  AddObjectArrayItem(@rr,"Properties","ListID")
  AddObjectArrayItem(@rr,"Properties","Status")

  set @sfp1 = CreateObject("SimpleFilterPart")
  SetObjectProperty(@sfp1,"Property","SubscriberKey") 
  SetObjectProperty(@sfp1,"SimpleOperator","equals")
  AddObjectArrayItem(@sfp1,"Value",@email)

  set @sfp2 = CreateObject("SimpleFilterPart")
  SetObjectProperty(@sfp2,"Property","ListID")
  SetObjectProperty(@sfp2,"SimpleOperator","equals")
  AddObjectArrayItem(@sfp2,"Value","Your Publication ListID")

  set @cfp = CreateObject("ComplexFilterPart")
  SetObjectProperty(@cfp,"LeftOperand", @sfp1)
  SetObjectProperty(@cfp,"LogicalOperator", "AND")
  SetObjectProperty(@cfp,"RightOperand", @sfp2)

  SetObjectProperty(@rr,"Filter",@cfp)
  //OutputLine(Concat(@rr,'@rr'))
  //OutputLine(Concat(@cfp,'@cfp'))

   set @ListSubObj = InvokeRetrieve(@rr,@rrStatus,@rrRequestID)
   //OutputLine(Concat(rowCount(@ListSubObj),' @ListSubObj'))
   //OutputLine(Concat(@ListSubObj,' @ListSubObj'))

   if rowCount(@ListSubObj) > 0 then 
     var @row
     set @row = row(@ListSubObj, 1)
     set @status = field(@row,'Status')
        if @status != "Active" then
        //USER HAVE ALREADY UNBSUBSCRIBED OR NEVER CONFIRMED
         SET @err = 2
     else
        //SET USER STATUS TO UNSUBSCRIBED IN THE LIST
         VAR @ts_sub
         SET @ts_sub = CreateObject("Subscriber")
         SetObjectProperty(@ts_sub, "EmailAddress", @email)
         SetObjectProperty(@ts_sub, "SubscriberKey", @email)

          // GET THE LIST
          SET @List = CreateObject("SubscriberList")
           SetObjectProperty(@List, "ID", "Your Publication ListId")
           SetObjectProperty(@List, "Status", "Unsubscribed")


        // ADD THE LIST TO CONTACT
           AddObjectArrayItem( @ts_sub, "Lists", @List )
        // UPDATE THE CONTACT
            InvokeUpdate(@ts_sub)
            SET @err = 0
         endif
     else 
   OutputLine(Concat(@email,' is a error 1!'))
      SET @err = 1
  endif

  else
    OutputLine(Concat(@email,' is a error 1.2!'))
     SET @err = 1
  endif 

 ]%%
0

@Yashasvi Pandey try like this

<script type="text/javascript" runat="server" >
             Platform.Load("Core","1");
        var lue, lue_prop, Response;

        lue = Platform.Function.CreateObject("ExecuteRequest");
        Platform.Function.SetObjectProperty(lue,"Name","LogUnsubEvent");

        //For accounts using the subscriber key functionality
        lue_prop = Platform.Function.CreateObject("APIProperty");
        Platform.Function.SetObjectProperty(lue_prop, "Name", "SubscriberKey");
        Platform.Function.SetObjectProperty(lue_prop, "Value", @email);
        Platform.Function.AddObjectArrayItem(lue, "Parameters", lue_prop);



        lue_prop = Platform.Function.CreateObject("APIProperty");
        Platform.Function.SetObjectProperty(lue_prop, "Name", "JobID");
        Platform.Function.SetObjectProperty(lue_prop, "Value", your jobid);
        Platform.Function.AddObjectArrayItem(lue, "Parameters", lue_prop);

        lue_prop = Platform.Function.CreateObject("APIProperty");
        Platform.Function.SetObjectProperty(lue_prop, "Name", "ListID");
        Platform.Function.SetObjectProperty(lue_prop, "Value", "21735");
        Platform.Function.AddObjectArrayItem(lue, "Parameters", lue_prop);

        lue_prop = Platform.Function.CreateObject("APIProperty");
        Platform.Function.SetObjectProperty(lue_prop, "Name", "Reason");
        Platform.Function.SetObjectProperty(lue_prop, "Value", "Profile Center Unsubscribe");
        Platform.Function.AddObjectArrayItem(lue, "Parameters", lue_prop);

        var statusAndRequest = [0,0];

        Response = Platform.Function.InvokeExecute(lue, statusAndRequest);


       </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.