All posts

Send Phoma Flow Results to External APIs Using the HTTP Request Step

Send Phoma Flow Results to External APIs Using the HTTP Request Step

Why push flow results out of Phoma?

Phoma runs flows locally on your Windows machine and the Android devices you own. That keeps data private and costs predictable, but it also means the results — pass/fail status, extracted text, screenshots, timing — stay inside the app unless you export them. Sending those results to an external system unlocks several practical workflows:

  • Centralised test dashboards – push every run into a test‑management tool (TestRail, Zephyr, a custom DB) so the whole team sees a single source of truth.
  • CI/CD gates – a failing flow can POST a payload that triggers a pipeline step, blocks a merge, or opens a ticket.
  • Audit trails – store raw screenshots and element‑tree snapshots in object storage for later regression analysis.
  • Real‑time alerts – forward critical failures to Slack, Teams, or PagerDuty via a webhook.

All of this is possible with Phoma’s HTTP Request step, which lets you call any REST endpoint from inside a visual flow — no code, no external scripts.

Prerequisites

Before you start, make sure you have:

  1. Phoma installed on Windows (free tier is enough).
  2. At least one Android device connected via USB or Wi‑Fi ADB and visible in Phoma.
  3. A flow that already performs the actions you want to measure (login, data entry, smoke test, etc.).
  4. An HTTP endpoint that accepts POST (or PUT/PATCH) with a JSON body. It can be a public webhook, an internal API, or a serverless function.
  5. Network reachability from the Windows host to the endpoint (firewall, VPN, proxy).

Understanding the HTTP Request step

The HTTP Request step is a first‑class flow action, just like Tap, Swipe, or Wait for Element. When the flow reaches it, Phoma builds the request on the Windows host, sends it, and optionally stores the response for later steps (conditions, logging, branching).

Key configurable fields:

Field Purpose Typical value
Method HTTP verb POST (most common)
URL Full endpoint, can contain variables https://api.example.com/phoma/results
Headers Key‑value pairs, e.g. authentication, content‑type Authorization: Bearer {{secrets.api_token}}
Body JSON payload; you can embed any flow variable See example below
Timeout (ms) Max time to wait for a response 10000
Store response as Variable name for the response body / status http_response

Tip: Phoma evaluates variables (double‑curly syntax) just before sending the request, so you can include dynamic data such as the device serial, current timestamp, or a base‑64 screenshot.

Step‑by‑step: Add an HTTP Request step to a flow

  1. Open the flow in Phoma’s visual builder.
  2. Drag an HTTP Request step from the palette onto the canvas, placing it after the last functional step (e.g., after a Text Assertion or Screenshot).
  3. Configure the basics:
    • Method → POST
    • URL → your endpoint (e.g., https://hooks.slack.com/services/XXX/YYY/ZZZ for a Slack webhook).
    • Headers → add Content-Type: application/json and any auth header.
  4. Build the JSON payload in the Body editor. Use the variable picker (the {{ }} button) to insert flow‑level variables.
  5. Set Store response as to a name like post_result so you can inspect status codes later.
  6. Add a Condition step (optional) right after the HTTP Request to branch on post_result.status == 200.
  7. Save and run the flow on a single device to verify the request succeeds.

Example payload

{
  "flow_name": "{{flow.name}}",
  "device_serial": "{{device.serial}}",
  "run_id": "{{run.id}}",
  "timestamp_utc": "{{run.started_at_utc}}",
  "status": "{{flow.status}}",
  "duration_ms": "{{flow.duration_ms}}",
  "assertions": [
    {"name": "login_success", "passed": {{step.login_assertion.passed}}},
    {"name": "dashboard_loaded", "passed": {{step.dashboard_assertion.passed}}}
  ],
  "screenshot_base64": "{{step.final_screenshot.base64}}",
  "custom": {
    "build_number": "{{env.BUILD_NUMBER}}",
    "git_sha": "{{env.GIT_COMMIT}}"
  }
}

All {{…}} placeholders are replaced at runtime. Phoma exposes a rich set of built‑in variables (flow metadata, device info, step results, screenshots) and you can also inject environment variables from the Windows host ({{env.VAR_NAME}}).

Using variables effectively

Variable Description Example use
{{flow.name}} Name of the current flow Identify which test suite ran
{{device.serial}} ADB serial of the phone Correlate results per device
{{run.id}} Unique run UUID Deduplicate in the backend
{{step.<step_id>.passed}} Boolean result of a preceding assertion Build a pass/fail matrix
{{step.<step_id>.text}} Text read by a Read Text step Send scraped data
{{step.<step_id>.screenshot.base64}} Base64‑encoded PNG of a Screenshot step Attach visual proof
{{env.VAR}} Any Windows environment variable Inject CI build numbers

Authenticating with the API

Most production endpoints require authentication. Phoma does not store secrets, so you have two practical options:

  1. Environment variables on the Windows host – set PHOMA_API_TOKEN in the system or user environment, then reference it as {{env.PHOMA_API_TOKEN}} in the Authorization header.
  2. Phoma’s built‑in Secrets panel (Team/Business plans) – define a secret named api_token and use {{secrets.api_token}}. This keeps the token out of the flow file and allows rotation without editing flows.

Example header row:

Authorization: Bearer {{secrets.api_token}}
Content-Type: application/json

If your endpoint uses Basic Auth, encode username:password in base64 on the host and store the resulting string as a secret.

Handling success and failure

After the HTTP Request step, add a Condition step to act on the response:

{{post_result.status}} == 200
  • True branch – continue normal flow, maybe log a success screenshot.
  • False branch – trigger a Notification step (email, Slack webhook) or Fail Flow step to mark the run as failed in Phoma’s UI.

You can also inspect {{post_result.body}} for error details returned by the API.

Scheduling and running on multiple devices

Phoma’s Multi‑Device Run launches the same flow on every selected phone in parallel (or sequentially, if you prefer). Each device executes its own HTTP Request step, sending a payload that includes its unique {{device.serial}}. This means your backend receives one request per device per run — ideal for aggregating per‑device pass rates.

To schedule:

  1. Open the Scheduler tab.
  2. Create a new schedule, pick the flow, choose All devices or a device group.
  3. Set cron expression (e.g., 0 2 * * * for 02:00 daily).
  4. Enable Run only if devices are online to avoid stale runs.

The scheduler runs on the Windows host, so the machine must be awake and the Phoma service running.

Troubleshooting common issues

Symptom Likely cause Fix
Request times out Firewall / proxy blocks outbound traffic Allow Phoma (Phoma.exe) through Windows Firewall; configure proxy in Phoma Settings → Network.
401 Unauthorized Token expired or wrong header format Verify secret value; ensure Bearer prefix; check token scopes.
Payload too large Base64 screenshot exceeds API limit Resize screenshot step (Set screenshot quality to 50 %); or upload screenshot to object storage first and send only the URL.
SSL certificate error Self‑signed cert on internal API Add the CA to Windows Trusted Root Certification Authorities, or disable cert validation in Phoma Settings → Advanced (not recommended for production).
Variables not resolving Typo in variable name or step not executed yet Use the Variable Picker UI; ensure the referenced step runs before the HTTP Request.

Best practices

  1. Keep payloads lean – send only what the consumer needs. Large base64 images bloat logs and increase latency.
  2. Version your payload schema – add a schema_version field so downstream consumers can evolve without breaking.
  3. Idempotency – include {{run.id}} so the backend can deduplicate retries.
  4. Secure secrets – never hard‑code tokens in the flow; always use {{secrets.*}} or {{env.*}}.
  5. Test locally first – run the flow on a single device with a request bin (e.g., https://webhook.site) to inspect the exact JSON sent.
  6. Monitor API health – add a simple HTTP Request health‑check flow that runs every 5 minutes; alert on non‑2xx.

Next steps

  • Integrate with CI/CD – use the same HTTP Request step to post results to GitHub Actions, GitLab CI, or Azure DevOps via their APIs.
  • Build a dashboard – feed the JSON into Elasticsearch, Grafana, or a custom React app for real‑time visibility.
  • Explore conditional branching – combine the HTTP response with Condition and Loop steps to retry flaky actions before reporting failure.
  • Read the “Choose Stable Android Element Selectors for Phoma Flows” guide to make the upstream steps more reliable, so the data you send is trustworthy.

By wiring Phoma’s HTTP Request step into your existing tooling, you turn every automated run into a first‑class data point — no extra scripts, no cloud device farms, just the phones and the Windows machine you already own.