Script Parameterization

Script Parameterization

Want your scripts to use dynamic values instead of hardcoded data? You can reference values generated earlier in your test and pass them directly to your API calls.

How It Works

During test execution, Pie generates unique values like phone numbers, emails, and names. You can reference these values in your scripts using curly-brace syntax:

{{use the phone number generated}}

When Pie executes your script, it automatically replaces the placeholder with the actual generated value. If Pie generated a phone number at step two, your script at step five will use that exact number.

The Syntax

Use double curly braces with a descriptive reference inside:

{
  "phone_number": "{{use the unique phone number generated at the beginning of the test}}",
  "password": "{{use the password created during signup}}"
}

Naming Rules:

Keep your parameter names clear and consistent:

  • Use lowercase letters only
  • Use underscores between words
  • Keep names descriptive
✅ Do This❌ Not This
phone_numberPhoneNumber
access_tokenaccessToken
user_passwordPASSWORD

Examples

Example 1: Using Generated Test Data

Your test generates unique values during signup. Later, you need those same values in an API call:

In your script’s curl command:

"phone_number": "{{use the unique phone number generated at the beginning of the test}}"

Pie substitutes the actual generated value when the script runs.

Example 2: Using Password Values

Similar to other test data, passwords created during test flows can be referenced:

"password": "{{use the password created during signup}}"

You can reference any value that was generated or entered earlier in the test execution.

Example 3: Chaining API Responses

Scripts can pass values between each other. You’ll find this essential for multi-step authentication or setup flows:

  1. First script makes an API call and receives a response (like a challenge request ID)
  2. Second script uses that response value and returns something new (like an access token)
  3. Third script uses the token from the second script as a Bearer token in its Authorization header

You describe the sequence in your test steps, and Pie handles passing the values automatically.

Example 4: Using Tokens as Bearer Authentication

When your API requires authentication from a previous step:

curl -X POST "https://api.yourapp.com/endpoint" \
  -H "Authorization: Bearer {{use access_token from login_script}}" \
  -d ''

The access token from your earlier login script gets inserted automatically.

Best Practices

  • Reference values clearly. Use descriptive text inside the curly braces so it’s obvious what value you need.
  • Chain scripts logically. Make sure the script generating a value runs before the script that uses it.
  • Test with hardcoded values first. Confirm your API call works with static data, then add parameterization.
  • Keep naming consistent. Stick to lowercase and underscores throughout your scripts.

Troubleshooting

Parameter not being replaced?

  • Verify the value was generated in an earlier step
  • Make sure the step that generates the value completed successfully before your script runs
  • Check that your reference text matches what Pie expects

Script failing with parameterization?

  • Test your curl command with a hardcoded value first to confirm the API endpoint works
  • Add parameterization only after the basic script works
  • Check the response format from previous scripts if you’re chaining values

Values not passing between scripts?

  • Confirm the earlier script ran successfully and returned the expected response
  • Verify you’re referencing the correct field name from the response