Appearance
Link Relations
Every link in the API carries a relation type (rel) that tells you how the target resource is related to the current one. You use relation types — not URL patterns — to find the link you need.
How relation types are identified
Outside of the IANA-registered link relation types (which, unless otherwise stated, maintain the semantics defined in the registry), the API also defines its own relation types to aid navigation. They are identified by tags as defined in RFC 4151 and are, as such, URIs:
tag:flywire.com,2016:agents:api:relation:{name}When matching links in code, you compare the rel against the full tag URI — never against the short suffix in isolation.
Using relations
When encountering the hypermedia profile's links, you can expose them as actions in your UIs. If you're interacting with the API in a server-to-server scenario, your client will have to pick and execute the action itself, based on what is required next. You can do that by finding the href of the link with the relation you're interested in and following it (or whatever the relation calls for):
python
RELATION = "tag:flywire.com,2016:agents:api:relation:"
def find_link(response_json, relation):
return next(
link for link in response_json["links"]
if link["rel"] == f"{RELATION}{relation}"
and "anchor" not in link
)
insurance_link = find_link(root, "insurance-types")
response = requests.get(insurance_link["href"], headers=auth)javascript
const RELATION = "tag:flywire.com,2016:agents:api:relation:";
function findLink(body, relation) {
return body.links.find(
link => link.rel === `${RELATION}${relation}` && !link.anchor
);
}
const insuranceLink = findLink(root, "insurance-types");
const response = await fetch(insuranceLink.href, { headers: auth });TIP
When filtering links, also check for the absence of anchor if you want the link that applies to the resource itself rather than a specific part of it. See Anchoring.
Templated links
Some links are templates rather than ready-to-use URLs: their href is a URI Template (RFC 6570) with variables in braces. They let you go straight to a resource you already know the identifier of, for example a payment experience you created earlier:
json
{
"rel": "tag:flywire.com,2016:agents:api:relation:payment-experience-details",
"href": "https://api-platform.demo.flywire.com/agents/v2/payment-experiences/{id}",
"schemas": {
"href": "tag:flywire.com,2016:agents:api:schema:payment-experience-retrieval-href"
}
}A templated link carries a schemas object, which documents properties of the link with JSON Schemas. schemas.href is the schema of the input that expands the href: an object whose properties are the template's variables. It's given in one of two ways:
- An identifier (a URI string), as above. It names a schema documented in the reference, here
payment-experience-retrieval-href. The identifier isn't a link, so don't fetch it: look it up. - The schema itself, as a JSON object. Use it as it is.
To follow a templated link:
- Resolve the schema from
schemas.href. - Build the input: an object with the values you want to use, for example
{ "id": "3f0c9a4e-5b1d-4c2e-9f7a-2d8e1b6c4a10" }. Validate it against the schema, so you find out about a missing or malformed value before making a request. - Expand the template with that object, using an RFC 6570 library. Each variable takes the value of the input property with the same name, percent-encoded.
GETthe resulting URL.
Take the template from the link every time and only ever change it by expanding it: don't build the URL yourself.
python
# pip install jsonschema uritemplate
from jsonschema import Draft202012Validator, validate
from uritemplate import expand
# Schemas documented in the reference, by identifier.
SCHEMAS = {
"tag:flywire.com,2016:agents:api:schema:payment-experience-retrieval-href": {
"type": "object",
"properties": {"id": {"type": "string", "format": "uuid"}},
"required": ["id"],
"additionalProperties": False,
},
}
def follow_templated(link, values):
schema = link["schemas"]["href"]
if isinstance(schema, str):
schema = SCHEMAS[schema]
# The format checker makes `format` (e.g. `uuid`) count, not just types.
validate(values, schema, format_checker=Draft202012Validator.FORMAT_CHECKER)
return requests.get(expand(link["href"], values), headers=auth)
link = find_link(root, "payment-experience-details")
experience = follow_templated(link, {"id": experience_id}).json()javascript
// npm install ajv ajv-formats url-template
import Ajv from "ajv";
import addFormats from "ajv-formats";
import { parseTemplate } from "url-template";
// Schemas documented in the reference, by identifier.
const SCHEMAS = {
"tag:flywire.com,2016:agents:api:schema:payment-experience-retrieval-href": {
type: "object",
properties: { id: { type: "string", format: "uuid" } },
required: ["id"],
additionalProperties: false,
},
};
const ajv = addFormats(new Ajv());
async function followTemplated(link, values) {
let schema = link.schemas.href;
if (typeof schema === "string") schema = SCHEMAS[schema];
const valid = ajv.validate(schema, values);
if (!valid) throw new Error(ajv.errorsText());
return fetch(parseTemplate(link.href).expand(values), { headers: auth });
}
const link = findLink(root, "payment-experience-details");
const experience = await followTemplated(link, { id: experienceId }).then(r => r.json());Designed for end-user UIs
Not all relation types are designed for server-to-server communication. Some link relations — for example the payment IANA relation, or monitor, certificate-of-insurance, payment-receipt — point to user-facing pages or downloadable documents and are intended to be opened by the end user, not fetched programmatically.
State-dependent links
The set of links present in a response depends on the state of the resource and your agency's permissions. For example, cancel-insurance-policy only appears for policies that are active and eligible for cancellation. Never assume a link will be present — always check before acting on it.
Reference
The full list of relation types defined by the API lives in the Reference section:
- Common Relations — IANA-registered relations (
self,first,prev,next,last,payment, …) and shared extension relations - Payments Relations — extension relations specific to the Payments API
- Insurance Relations — extension relations specific to the Insurance API