URL data handling

Survey status & redirect

Two runtime helpers control how interviews leave the platform. `endSurvey()` terminates the interview — call it with no arguments (defaults to `terminate`) or with a single positional status string (`"complete"`, `"terminate"`, `"quotafull"`); no kwargs. `redirectUrl(url)` sends the respondent's browser to an external URL — works before `endSurvey` (suspend & return) or after (terminal redirect). The platform auto-appends the params it needs to round-trip a respondent.

Two helpers, one job

HelperEnds the interview?What it does
endSurvey(...)Yes — terminal.Marks the interview as ended with a status. Doesn’t redirect.
redirectUrl(url)No, by itself.Sends the respondent’s browser to a URL. Pair with endSurvey(...) for terminal redirects; use alone for non-terminal hand-offs (Sawtooth conjoint, calculator, partner-hosted task) where the respondent comes back.

The division is clean: endSurvey decides the outcome, redirectUrl decides where the browser goes. Most surveys use both at the end of the flow — endSurvey to record the completion status, then redirectUrl to bounce the respondent back to the panel.

- script: |
    endSurvey("complete")
    redirectUrl("https://panel.example.com/end")

Both helpers run from any Python execution zone the runtime attaches them to — - script: is the everyday home, but they’re also reachable inside validation: blocks. Prefer - script: for clarity — it keeps end-of-flow logic in one obvious place and stops a stray endSurvey() from firing every time a respondent retries an answer. Both helpers write to a system event log that lands in the export as an audit trail of exactly which calls fired and in what order.

endSurvey(...) — finish the interview

endSurvey(...) ends the interview with a status. The outcome is terminal — no further survey questions render after this call. (In test mode, the runtime may stamp a visible exit- display question that the builder anchors to, so authors can see where the run finished. Live sessions skip past that step.) The helper does not redirect on its own — that’s redirectUrl(...)’s job.

The four call forms

endSurvey(...) takes either no arguments or a single positional status string — no keyword arguments, no other parameters. The no-arg form is a canonical call form in its own right, not just a shorthand example.

- script: |
    endSurvey()              # terminate (default — most common, screener branches)
    endSurvey("complete")    # complete — clean shorthand
    endSurvey("quotafull")   # quotafull
    endSurvey("terminate")   # terminate (explicit form)
StatusMeaning
completeRespondent finished the interview successfully.
terminateRespondent was screened out, disqualified, or otherwise terminated.
quotafullA quota cell the respondent qualified for is already full.

Matching is case-insensitive — "Complete", "COMPLETE", and "QuotaFull" all parse and normalise to lowercase before storage. Pick the canonical lowercase form and stick with it.

endSurvey() with no args defaults to terminate

The everyday “kick this respondent out” shorthand. When the status is omitted, the runtime treats it as terminate:

# These two are equivalent:
- script: |
    endSurvey()

- script: |
    endSurvey("terminate")

Use the no-arg form for screenouts and disqualifications where naming the status would be noise. For complete and quotafull, spell the status out — the no-arg form is only a shortcut for terminate, the most common branch.

Identifiers come from the request, not from arguments

There are no kwargs on endSurvey(...) for respondent_id, interview_id, return_key, or resume_token. The runtime captures all of these from the entry URL (via request.param(...)) and records them against the response automatically — authors don’t pass them in.

If you need to round-trip a panel-supplied identifier into the redirect URL, splice it into the URL you pass to redirectUrl(...) (under a non-reserved key like panel_rid=).

Sending a respondent out and back mid-survey

endSurvey(...) is terminal — once it fires the interview is over. If you need to send the respondent to an external tool and have them come back to finish the rest of the survey, reach for redirectUrl(...) without calling endSurvey(). The platform suspends the interview, the respondent does the external task, and they return to the next question.

Errors

Error codeCause
endsurv-invalid-statusThe status string is outside the three-value enum. The error message names the allowed values and points authors at redirectUrl(...) for non-terminal hand-offs.
endsurv-bad-argendSurvey(...) called with something that isn’t a string or None (e.g. a number, list, dict, or boolean). Valid forms: endSurvey(), endSurvey("complete"), endSurvey("terminate"), endSurvey("quotafull").
endsurv-in-conditionendSurvey(...) called from inside a flow predicate (e.g. - if endSurvey(...):). Move it into a - script:.

On any of these, the interview is not ended — ended stays false so a typo doesn’t force-complete every respondent. The error appears in the runtime log; fix it before launch.

redirectUrl(...) — browser redirect

redirectUrl(url) sends the respondent’s browser to a URL. It’s the only way to redirect — used both for terminal hand-offs (paired with endSurvey(...) to bounce the respondent back to the panel) and for non-terminal ones (Sawtooth conjoint, image annotator, third-party calculator — the respondent does the external task and returns).

- script: |
    redirectUrl(
        "https://sawtooth.example.com/conjoint?project=42"
        + "&Qconcept=" + QConcept.value
        + "&lang=" + QLang.value
        + "&gender=" + QGender.value
    )

Single positional argument: the URL string you’ve built. There are no kwargs.

What the platform auto-appends

The platform automatically appends three params to every URL redirectUrl(...) builds — programmers never set these by hand:

ParamValuePurpose
ridThe internal respondent ID.Identifies the respondent on return.
tokenA unique persistent validator.Authenticates the return — the platform won’t resume without it.
projectidThe internal project identifier.Routes the return to the correct survey.

These three keys are always set, overwriting any matching keys you happen to have included in the URL. Don’t try to set rid= / token= / projectid= yourself — they’ll be replaced on the way out. If you need to round-trip a panel-supplied ID, pass it through under a different key (e.g. panel_rid=).

In preview (where there’s no real session), the platform fills the three with placeholders so authors can sanity-check the URL while building the survey:

ParamPreview value
ridpreview-respondent
tokenpreview-token
projectidpreview-project

Terminal vs. non-terminal — same call, different timing

redirectUrl(...) behaves slightly differently depending on whether endSurvey(...) has already fired in the same script:

ScenarioWhat happens
redirectUrl(...) alone, no prior endSurvey()The interview is suspended. The respondent’s browser navigates to the URL; on return, the platform resumes them at the next available question.
endSurvey(...) then redirectUrl(...)The interview is ended. In a live session, the respondent’s browser navigates to the URL. In test mode (preview / builder), advancing past the exit-display page lands on a terminal redirect screen that shows the built URL — the builder doesn’t actually navigate away, so authors can copy or inspect the URL.

The deferred-redirect path means test runs surface the URL on a terminal screen for inspection, while live sessions hit the redirect for real. Authors don’t need to handle the two cases differently — write the same two-line script and the runtime takes care of the timing.

Errors

Error codeCause
redirecturl-missing-urlredirectUrl() called with no argument.
redirecturl-invalid-urlThe URL string isn’t a valid URL.
redirecturl-in-conditionredirectUrl(...) called from inside a flow predicate (e.g. - if redirectUrl(...):). Move it into a - script:.

On error, no system event is logged — the call simply fails. Fix the URL.

The system event log

Every endSurvey(...) and redirectUrl(...) call writes a row to the survey’s system event log. Sample shapes:

{ "type": "end",          "status": "complete",                  "seq": 0 }
{ "type": "redirect_out", "url":    "https://...",               "seq": 1 }
{ "type": "redirect_out", "url":    "https://...", "deferred": true, "seq": 2 }
FieldMeaning
type"end" for endSurvey, "redirect_out" for redirectUrl.
statusOn end rows: the lowercased status string.
urlOn redirect_out rows: the fully-built URL with platform params already appended.
deferredOn redirect_out rows fired after endSurvey() in test mode: present and true. Absent on immediate live-mode redirects and on non-terminal redirects.
seq0-indexed position in the event log.

There’s no author-facing accessor for the log inside the survey runtime — it’s a system-side audit trail, not a piece of state you read or write from script. In the data export, the full sequence lands as a single hidden system column on the respondent’s row, so analysts can reconstruct exactly what fired and in what order.

Use it as an audit trail

The everyday use case is auditing — reconstructing exactly which end / redirect calls fired across a batch of respondents. For a fielded survey of 200 respondents, the system column might break down as:

  • 180 rows with [{type:'end', status:'complete', seq:0}, {type:'redirect_out', url:'...', seq:1}]
  • 15 rows with [{type:'end', status:'terminate', seq:0}, {type:'redirect_out', url:'...', seq:1}]
  • 5 rows with [{type:'end', status:'quotafull', seq:0}, {type:'redirect_out', url:'...', seq:1}]

No digging through raw transcripts to figure out what fired when. One column, one source of truth.

print(...) calls don’t go through the system event log — they have their own debug log. Only endSurvey and redirectUrl write here.

Common patterns

Panel completion at survey end

The everyday “respondent finished, ping the panel” close — end the interview with complete, then bounce the respondent back to the panel.

- script: |
    endSurvey("complete")
    redirectUrl("https://panel.example.com/end")

The panel partner sees the respondent return with the platform- appended rid / token / projectid params. If the partner needs their own original ID echoed back, splice it under a non-reserved key:

- script: |
    endSurvey("complete")
    redirectUrl(
        "https://panel.example.com/end"
        + "?panel_rid=" + request.param("rid")
    )

Mid-survey screenout

A screening question disqualifies the respondent — terminate and bounce them back to the panel’s screenout endpoint.

- qid: QAge
    type: number
    text: How old are you?
    min: 0

- if QAge.value < 18:
    - script: |
        endSurvey()
        redirectUrl("https://panel.example.com/screenout")

endSurvey() (no args) is the screenout shorthand — defaults to "terminate".

Quota-full at the end of qualification

When a quota is full, end with quotafull and route to the partner’s quota-full endpoint.

- if hQuotaFull.value == 1:
    - script: |
        endSurvey("quotafull")
        redirectUrl("https://panel.example.com/quotafull")

Hand off to an external conjoint exercise

The textbook non-terminal redirectUrl use. Send the respondent to Sawtooth (or any external tool) with the values it needs to render the right exercise; the platform auto-appends rid / token / projectid so they can return.

- script: |
    redirectUrl(
        "https://sawtooth.example.com/conjoint?project=42"
        + "&Qconcept=" + QConcept.value
        + "&lang=" + QLang.value
        + "&gender=" + QGender.value
    )

Note there’s no endSurvey() here. The respondent does the conjoint task, returns via the platform’s resume URL, and lands on the next question in the flow.

Outcome dispatch — different terminations to different URLs

- script: |
    if hOutcome.value == "qualified":
        endSurvey("complete")
        redirectUrl("https://panel.example.com/end")
    elif hOutcome.value == "quota_full":
        endSurvey("quotafull")
        redirectUrl("https://panel.example.com/quotafull")
    else:
        endSurvey("terminate")
        redirectUrl("https://panel.example.com/screenout")

Compute the outcome upstream into a hidden question (hOutcome here), then dispatch on it at the end. Keeps the end-of-flow logic readable.

Behaviour notes

endSurvey(...) doesn’t break out of script execution

Calling endSurvey(...) from inside a - script: doesn’t stop the rest of that script from running. It marks the interview as ended; the runtime processes the remaining lines normally and only stops rendering further questions / pages when the script returns. This is exactly what makes the endSurvey(...)-then-redirectUrl(...) pattern work — both calls execute, the runtime sequences them correctly.

- script: |
    endSurvey("complete")
    redirectUrl("https://panel.example.com/end")
    print("This still runs.")
    hLastSeen.set(datetime.datetime.now().isoformat())
    # ...all of these execute before the runtime moves on.

If you have post-end housekeeping, put it before the endSurvey call to keep the intent clear.

Last endSurvey(...) wins

If a script reaches multiple endSurvey(...) calls, the system event log records all of them but the last call is what the platform acts on. Order branches so the call that should win is the one actually reached last.

Don’t call from inline if: conditions

Both helpers explicitly reject being called inside a flow predicate — the runtime errors with endsurv-in-condition or redirecturl-in-condition and refuses to fire. Keep both helpers inside - script: blocks where they belong.

# Don't — both of these error at runtime.
- if endSurvey("terminate"):
- if redirectUrl("https://..."):

redirectUrl(...) with auto-appended params overwrites yours

If you happen to write redirectUrl("https://x.com/?rid=42"), the platform’s rid= overwrites your 42 on the way out. Don’t include rid / token / projectid in the URL you build — they’re not yours to set. Pick a different key name when you need to round-trip a panel-supplied identifier.

What endSurvey() doesn’t do

  • It doesn’t redirect — that’s redirectUrl(...)’s job. To send the respondent somewhere on completion, call both: endSurvey("complete") then redirectUrl("...").
  • It doesn’t navigate within the survey — there’s no equivalent of a goto:. The interview ends.
  • It doesn’t write hidden-question values for you. Set hStatus.set("complete") yourself if you want the status in the export alongside the system event log.

See also

  • Query params — request.param(...) is the input side; redirectUrl(...) is the output side
  • Scripts — - script: is the recommended home for both helpers
  • Routing — - if: is how you reach the right endSurvey(...) for each outcome
  • Quotas — quota-full responses use endSurvey("quotafull") paired with a quota-full redirectUrl(...)