Block reference / Web interaction
Page request
Send an HTTP request from the open tab, with the page's cookies, and store the answer.
Only in
WarpX Browser
Page request sends one request from inside the tab the run is on, as the page's own scripts would. It goes out with the page's cookies, including the HttpOnly ones no script can read, so it is signed in wherever the profile is signed in. Use it to call a site's own API, such as the endpoint behind a button, when HTTP request would arrive without the session. A relative address such as /api/graphql/ is the page's own site. A failed status can go down the block's second output.
Settings
- Description
A note shown under the block's name on the canvas. It has no effect on the run.
ExampleAsk for the account's name- Method
GET, POST, PUT, PATCH or DELETE. New blocks start at POST. GET sends no body.
ExamplePOST- URL*
Where to send it. A relative address is resolved against the page the run is on, so
/api/graphql/onhttps://www.facebook.com/goes tohttps://www.facebook.com/api/graphql/. A full address works too. References such as{{variables.userId}}are filled in first.Example/api/graphql/- Headers (one per line, Name: value)
One header per line, written
Name: value. A line with no colon, or with nothing before it, is skipped. References are filled in.ExampleX-FB-Friendly-Name: ProfileQuery- Bodywhen Method is not GET
How the body is sent: None, Form (application/x-www-form-urlencoded), JSON or Raw text. New blocks start at Form. For Form and JSON, the matching
Content-Typeis set unless Headers already has one; Raw text sets none.ExampleForm (application/x-www-form-urlencoded)- Bodywhen Body is not None
The box under Body: what to send. For Form, write
a=1&b=2, or a JSON object such as{"a": "1", "b": "2"}, which is encoded for you, so a value with&or=in it cannot break the form apart. For JSON and Raw text, it is sent as written. References are filled in first.Examplefb_dtsg={{variables.fb_dtsg}}&av={{variables.userId}}&doc_id=1234567890- Response
How to read the answer: JSON, JSON per line (NDJSON) - a list, which reads one JSON value per line and hands on a list of them, or Text. It only matters when you store the answer.
ExampleJSON- Strip from the start (regular expression)
A regular expression taken off the start of the answer before it is read. Facebook puts
for (;;);in front of many of its JSON answers; write it asfor \(;;\);. Other sites' guards, such as\)\]\}', work the same way. Leave it empty when the answer starts with the JSON.Examplefor \(;;\);- Data path
The part of the answer to keep, for example
data.viewer.id. Leave it empty to keep the whole answer. Start it with$responseto reach the status and address too:$response.status,$response.url,$response.redirectedor$response.data.<path>.Exampledata.viewer.id- Timeout (millisecond, 0 for none)
How long to wait for the answer. New blocks start at
30000, thirty seconds. A request that runs out of time fails with "The request took longer than 30000 ms".Example30000- Assign to variable
Stores the answer, or the part at Data path, in a variable. On by default.
ExampleChecked- Variable namewhen Assign to variable is on
The variable to store it in. Read it later as
{{variables.profile}}.Exampleprofile- Insert to tablewhen the workflow has table columns
Writes the answer to a table column. A list becomes one row per item, unless the column's type is array. It only appears when the workflow's table has columns.
ExampleUnchecked- Select columnwhen Insert to table is on
The column to write to.
Examplename
Every block also has the shared block settings — a description, Disable block and what to do on an error. Fields that take text accept data from earlier blocks.
What it hands on
On a 2xx answer, the answer (or the part at Data path) goes to the variable and the column you ticked, and the block leaves by its main output. On an error status, such as 4xx or 5xx, it leaves by its second output when that is connected, and the log still marks the block as failed. With nothing connected there, the block fails with the status and its text, such as (403) Forbidden.
Example: Call Facebook's API as the signed-in account
- Start
- Open URL
- Get page source
- Get page source
- Page request
- Notification
- Add an Open URL block with
https://www.facebook.com/on a profile that is signed in. - Add a Get page source block with Regular expression (optional)
"DTSGInitialData",\[\],\{"token":"([^"]+)", and Assign to variable namedfb_dtsg. - Add a second Get page source block with
"USER_ID":"(\d+)", assigned touserId. - Add a Page request block. Keep Method at POST and set URL to
/api/graphql/. - Keep Body at Form and write
fb_dtsg={{variables.fb_dtsg}}&av={{variables.userId}}&doc_id=1234567890, with thedoc_idof the query you want. - Keep Response at JSON, tick Assign to variable and name it
result. - Connect the second output to a Notification block, so a refused request tells you instead of stopping the run.
Good to know
- It needs an open tab in the profile's browser. The request is the page's own, so it leaves through the profile's proxy and from the page's origin: a full address on another site only gets an answer if that site allows cross-site requests from this one.
- The answer is only read when Assign to variable or Insert to table is on. Otherwise the block only checks the status.
- An answer that is not what Response expects fails the block, naming what came back: "Expected JSON but the response was: ...", or for NDJSON the line that did not parse. Set Strip from the start if the JSON has something in front of it.
- A Data path that finds nothing fails the block with "Nothing at" the path, instead of storing an empty value.
- A request that cannot be sent at all, or runs out of time, fails the block rather than going down the second output. Use the block's error settings to carry on.
- After Switch frame into an iframe, the request is sent from that frame, and a relative address is that frame's site.
- A locked automation from the store may only send to the hosts in its listing. A relative address is the page's own site and is allowed; a full address on any other host fails with "This locked automation may only send to ...".
See also
- Get page source — Read the page's HTML, inline scripts included, or one value out of it with a regular expression.
- HTTP request — Sends an HTTP request to a URL and can store the response.
- JavaScript code — Run your own JavaScript in the page, and pass data back to the workflow.
- Cookie — Reads, sets or removes cookies in the profile's browser.