Documentation

Calling external APIs

Article

Calling external APIs

When and Why to Use

Use this to make outbound HTTP requests to approved external APIs during a survey. This is useful for:

  • Personalizing content based on real-time data
  • Validating input or IDs
  • Logging or syncing responses to external systems

⚠️ Note: All external domains must be allow-listed by MX8 Labs prior to use.

Configuration Options
ParameterTypeRequiredDefaultDescription
urlstryes-Full endpoint URL (must be allow-listed)
methodstryes-HTTP method: "GET" or "POST"
dataDictnoNoneData payload for POST requests
paramsDictnoNoneURL query parameters for GET requests
headersDictnoNoneAdditional HTTP headers (e.g. auth tokens)
timeoutintno10Timeout in seconds before request fails
Example Code
s.call_api( url="https://api.myservice.com/userinfo", method="GET", params={"user_id": respondent_id}, headers={"Authorization": "Bearer xyz123"} )

For a POST request:

s.call_api( url="https://api.myscorer.com/evaluate", method="POST", data={"answers": user_answers}, headers={"Content-Type": "application/json"} )
Notes
  • Only allow-listed domains will work — contact MX8 Labs to add new domains
  • call_api returns a StringResponse, which you can capture and use in follow-up logic
  • The function will raise a ValueError if an unapproved domain is used
  • Handle timeout errors and unexpected responses in your downstream logic as needed