Skip to main content

Function: call_api

Or bringing in other services

Updated over 3 weeks ago

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

Parameter

Type

Required

Default

Description

url

str

yes

-

Full endpoint URL (must be allow-listed)

method

str

yes

-

HTTP method: "GET" or "POST"

data

Dict

no

None

Data payload for POST requests

params

Dict

no

None

URL query parameters for GET requests

headers

Dict

no

None

Additional HTTP headers (e.g. auth tokens)

timeout

int

no

10

Timeout 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

Did this answer your question?