Stack Exchange
URL Passthrough parameters in cloudpage
I have a unsubscribe cloud page with ampscript code, so I have to pass some parameters to that landing page works.
Here you have the cloudpage ampscript code:
%%[
VAR @subId, @jobid, @reason, @lue, @lue_prop, @lue_statusCode, @overallStatus, @requestId, @Response, @Status, @Error

SET @subId = AttributeValue("_subscriberkey")
SET @jobid = QueryParameter("JID")
SET @emailAddress = AttributeValue("emailaddr")

SET @Subkey = QueryParameter("subkey") 
SET @jid = QueryParameter("jobid")
SET @Eml = QueryParameter("email")
SET @reason = QueryParameter("unsub-reason")
SET @reasondesc = QueryParameter("unsub-reason-desc")

IF NOT EMPTY(@reasondesc) THEN
  SET @reason = @reasondesc
ENDIF

IF NOT EMPTY (@Subkey) AND NOT EMPTY (@jid) AND NOT EMPTY(@Eml) AND RequestParameter("submitted") == "true" THEN

SET @lue = CreateObject("ExecuteRequest")
SetObjectProperty(@lue,"Name","LogUnsubEvent")

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "SubscriberKey")
SetObjectProperty(@lue_prop, "Value", @Subkey)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "EmailAddress")
SetObjectProperty(@lue_prop, "Value", @Eml)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "jobid")
SetObjectProperty(@lue_prop, "Value", @jid)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "Reason")
SetObjectProperty(@lue_prop, "Value", @reason)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

SET @Response = Row(@lue_statusCode, 1)
SET @Status = Field(@Response,"StatusMessage")
SET @Error = Field(@Response,"ErrorCode")

SET @updatedDate = Now(1)
UpsertDE("my de name",1,"Subscriberkey", @Subkey, "Email", @Eml, "JobID", @JID, "unsub-reason", @reason, "Data", @updatedDate)
ELSE
outputline (concat("No Unsub",""))
ENDIF
]%%

The problem is we have a customized footer in html setuping in "Account Settings" no SFMC. When I insert the ampscript code below in footer
Here I insert into customized footer:
%%[
SET @link = Concat(CloudPagesURL(xxxx), "&JID=", jobid)
]%%

And here I insert into the unsubscribe footer link:
a href="%%=RedirectTo(v(@link))=%%" 

But when I send the e-mail and I click the unsubscribed link, the landing page doesnt open. I dont know why it happens. Otherwise, if I put the ampscript code into the email body, when I click on the unsubscribed footer link, the landing page open and works fine.
Its seems that customized footer in the Account Settings, somehow cant get this parameter. Anyone can help?

Try just the CloudPagesURL function in the footer, no need to attach the JobId as it will be passed automatically with all required attributes.
Put this in your unsubscribe link:
<a href="%%=CloudPagesURL(xxx)=%%">unsubscribe</a>

And on the CloudPage, use the following:
<script runat="server">
Platform.Load("Core","1.1.1");
try{
</script>

%%[
VAR @reason, @lue, @lue_prop, @lue_statusCode, @overallStatus, @requestId, @Response, @Status, @Error


SET @Subkey = AttributeValue("_subscriberkey")
SET @jid = AttributeValue("jobid")
SET @Eml = AttributeValue("emailaddr")
SET @reason = "One-click unsubscribe"


IF NOT EMPTY (@Subkey) AND NOT EMPTY (@jid) AND NOT EMPTY(@Eml) AND RequestParameter("submitted") == "true" THEN

SET @lue = CreateObject("ExecuteRequest")
SetObjectProperty(@lue,"Name","LogUnsubEvent")

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "SubscriberKey")
SetObjectProperty(@lue_prop, "Value", @Subkey)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "EmailAddress")
SetObjectProperty(@lue_prop, "Value", @Eml)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "jobid")
SetObjectProperty(@lue_prop, "Value", @jid)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "Reason")
SetObjectProperty(@lue_prop, "Value", @reason)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)

SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

SET @Response = Row(@lue_statusCode, 1)
SET @Status = Field(@Response,"StatusMessage")
SET @Error = Field(@Response,"ErrorCode")

SET @updatedDate = Now(1)
UpsertDE("my de name",1,"Subscriberkey", @Subkey, "Email", @Eml, "JobID", @JID, "unsub-reason", @reason, "Data", @updatedDate)
ELSE
outputline (concat("No Unsub",""))
ENDIF
]%%

<script runat="server">
}catch(e){
 Write(Stringify(e));
}
</script>

Not sure if you need the AND RequestParameter("submitted") == "true" part - it's only required if you have a form on that CloudPage and want the unsubscribe to be processed on form submission. If that's not the case, I'd remove it.
More on the CloudPagesURL function here: https://ampscript.guide/cloudpagesurl/

I've tried this before, but the JobId don't pass automatically ;/

I’ve edited my answer

I tried your suggestion, but after click on the unsubscribe link to go the page, appears "500 - internal server error" :(

Ok I found one more mistake in your script, please see edited answer - you seed to set @subkey to grab the _subscriberkey. Also, instead of using the QueryParameter functions to get values passed from email, you can just use AttributeValue

The same error 500... the page does not open.
I guess this html footer in accounts settings does not get these parameters, because its dont make any sense.
The lp just work if I set @jobid int the html body email, but its not functional, its impossible open all the emails and put this ampscript code into them.

I've edited your original script and added some error handling, can you try now and see what it says?

Same 500 error :(

If you prefer I could post the entire html code including the html email, maybe can helpful.
