Extract custom fields alongside the normalized metadata
Extract custom fields from the same metadata API request that returns the title, description and image. Open Graph tags cover the basics, but the value your product needs, a price, a rating, a stock status or a list of headings, usually lives somewhere else on the page. Declare it as a rule and it comes back typed, next to the normalized fields.
Open Graph metadata gets you close, not all the way
A link preview needs title, description and image, and the Metadata API normalizes those from Open Graph, Twitter Cards, JSON-LD and the HTML itself. A product card, a job listing, a recipe or a directory entry needs one or two more values that no standard tag carries.
The common workaround is a second scraper: fetch the page again, parse it with your own selectors, and keep two caches and two failure modes in sync. If you want to scrape a price with the Open Graph data of the same product, you end up loading the page twice.
The data parameter takes extraction rules: a CSS selector, the attribute to read and the type to validate as. Passed with a metadata request, the rules ride along and the response carries both the normalized fields and yours. The defining rules guide covers the full grammar.
How to add a CSS selector field to a metadata API request
A rule answers three questions: which element, what to read from it, and how to validate it. Add as many rules as you need to one request; each becomes a key in the response.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { title, image, price } = await microlink.metadata(
'https://example.com/product',
{
data: {
price: { selector: '.price', attr: 'text', type: 'number' }
}
}
)The normalized fields come back as usual. price is read from the first element matching .price and parsed as a number.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { title, rating, headings } = await microlink.metadata(
'https://example.com/product',
{
data: {
rating: { selector: '[itemprop=ratingValue]', attr: 'content', type: 'number' },
headings: { selectorAll: 'h2', attr: 'text' }
}
}
)selectorAll returns every match as an array. Each rule validates independently, so a missing rating does not affect the headings.
curl 'https://api.microlink.io/?url=https%3A%2F%2Fexample.com%2Fproduct&data.price.selector=.price&data.price.attr=text&data.price.type=number'Rules flatten to data.price.selector, data.price.attr and data.price.type query parameters, so the request works from any language or from the CLI.
- data Object of custom extraction rules, evaluated next to the normalized metadata.
- selector Which element: the first match of a CSS selector.
- selectorAll Every match of a CSS selector, returned as an array.
- attr What to read: any HTML attribute, or text, html, outerHTML, markdown, json or val. Default html.
- type How to validate: number, url, date, image, email, boolean and more. Default auto.
- meta Pick which normalized fields to keep alongside your rules.
A rule that matches nothing, or whose value fails its type, resolves to null, so destructuring is always safe. When you want only your fields and none of the normalized ones, call extract instead.
Why extracting custom fields with rules beats a second scraper
The normalized fields and your fields come from the same fetch, the same cache entry and the same request.
The same rules can override a normalized field when a page ships a wrong title or no og:image.
An array of rules is a fallback chain: the first rule that yields a valid value wins, so a layout change degrades gracefully.
When not to: if the page already exposes the value in JSON-LD or Open Graph, the normalized metadata probably has it, so check the default response before adding a rule. When you need the whole article rather than one field, use Markdown with metadata frontmatter.
FAQ
Can I get metadata and custom fields in one request?
What types can a custom metadata field have?
How do I extract a list of values next to the metadata?
How do I scrape a price with the Open Graph metadata of a product page?
Can a custom metadata rule read content that only appears after JavaScript runs?
Solve the next problem with the same API
Fix missing or wrong og:image
Only the fields you need
Metadata from single-page apps
Brand colors from images
Markdown with metadata frontmatter
LLM context from any URL
Ready to extract the fields you need?
Normalized metadata plus your own rules in one call. Start on the free tier and add your first custom field today.