Page data source in redirect endpoint reply

Hi there,
I have been using the endpoint reply to display an experience page with some JSON pageData, as described below:

Now I need to add a parameter to this experience page, so I’m using the redirect type but I can’t figure out how to include the pageData?
image

Hope this makes sense?
Cheers
Jules

Hey @Jules_Huguenin!

Redirects don’t usually contain bodies. When you reply with a redirect, you’re sending the browser a 301 or 302 status code and your redirect URL is sent in the location header. The browser will then immediately make a new request to whatever URL you provided (almost as if the user directly typed that new URL in the address bar, except it’s done automatically).

This redirect will cause the browser to make a new request to your GET /preventive-maintenance/{deviceId} endpoint. That endpoint triggers a workflow and that’s where you’ll add page data and render the final page.

1 Like

Alternatively, if you are asking about adding a query parameter to the redirect URL, that would be done using the following syntax:

/preventive-maintenance/{{data.params.deviceId}}?PMJobError={{encodeURIComponent errorMessage}}&myOtherParam=foobar

These parameters will be available on request.query.PMJobError and request.query.myOtherParam.

1 Like

Great! Thanks @Brandon_Cannaday,
With your pointers I did this:

> /preventive-maintenance/{{data.params.deviceId}}?error=true

and checked the parameter using this:

{{#if request.query.error}}
{{component "errorAlert" "We couldn't add the preventive maintenance job number"}}
{{/if}}

It works as I want it to, thanks for the help :+1:
Cheers
Jules

Awesome!

That’s a common pattern I do as well. For example, if I’m building a form to edit a device, I may have the following:

  1. GET /device/{id}/edit (renders form)
  2. POST /device/{id} (accepts POST data from form)
  3. If successful, redirect to /device/{id}/edit?success=true
  4. If unsuccessful, redirect to /device/{id}/edit?error=<message>

I can then show a success or failure message to the user.

There’s a lot of reasons the POST /device/{id} workflow could fail depending any number of validation rules (missing fields, etc). I generally like to add a message (or error code) to the error query parameter with helpful details for the user whenever possible.

1 Like