Get started
Streaming responses
Searches that ask several sources at once stream results as each source answers, using Server-Sent Events (SSE). The first results usually arrive in a second or two.
Which endpoints stream
| Endpoint | Events, in order |
|---|---|
| POST /v1/search | progress, result, error, complete |
| POST /v1/search/multi-city | leg_progress, leg_result, positioning, complete |
| POST /v1/hotels/search | progress, result, complete |
| POST /v1/cars/search | progress, result, complete |
| POST /v1/cruises/search | progress, result, complete |
| POST /v1/calendar/search | calendar_day, complete |
Each reference page lists what every event carries. Test keys stream sample events in the same format.
Event format
The response has Content-Type: text/event-stream. Each event is an event: <name> line, then a data: <json> line, then a blank line. complete is always the last event.
A flight search stream (shortened)
event: progress
data: {"source":"google_flights","status":"searching","result_count":0}
event: result
data: {"id":"off_8f2c…","segments":[{"departure_airport":"JFK","arrival_airport":"NRT","departure_time":"2027-01-23T11:05:00","arrival_time":"2027-01-27T14:30:00","carrier":"NH","carrier_name":"ANA","flight_number":"NH9","duration_minutes":805}],"price_cash":1284.4,"price_currency":"USD","price_points":85000,"points_program_name":"ANA Mileage Club","cabin_class":"economy","stops":0,"total_duration_minutes":805,"source":"google_flights","deep_link":"https://pointifytravels.com/search?…","cpp":1.4}
event: progress
data: {"source":"google_flights","status":"complete","result_count":42}
event: complete
data: {"total_results":42}
Reading a stream
Read the body as it arrives, split it on blank lines and parse each data line as JSON. With curl, pass -N to turn off buffering.
POST /v1/search
const res = await fetch("https://api.pointifytravels.com/v1/search", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.POINTIFY_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"origin": "JFK",
"destination": "NRT",
"departure_date": "2027-01-23",
"trip_type": "one_way",
"cabin_class": "economy"
}),
});
// Server-Sent Events: read the stream line by line.
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
for (;;) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
let i;
while ((i = buffer.indexOf("\n\n")) >= 0) {
const block = buffer.slice(0, i);
buffer = buffer.slice(i + 2);
const event = /^event: (.*)$/m.exec(block)?.[1];
const data = /^data: (.*)$/m.exec(block)?.[1];
if (event && data) console.log(event, JSON.parse(data));
}
}Tips
- Keep the connection open until
complete. Set your HTTP client's read timeout well above a few seconds; slow sources can take longer than fast ones. - A source that fails sends a
progressevent withstatus: "error"; the rest of the search continues. On flight search, anerrorevent means the search failed as a whole. - Results arrive unsorted. Sort on your side, for example by price or duration.
- An invalid request gets a normal
422JSON response instead of a stream, so check the status before reading events. See Errors. - Browsers' EventSource cannot send POST bodies or headers. Read streams on your server with fetch or requests.