Mapping API fields

Field mapping is the process of connecting data from your API response to the template display elements. This article explains how to map fields and apply transformations to format data the way you want it displayed.

Understanding Field Mapping

When you receive data from an API, it comes as structured information. For example, an API might return:

{ "id": 123, "title": "Blue Sneakers", "description": "Comfortable blue athletic shoes", "price": 89.99, "image_url": "https://example.com/shoe.jpg", "category": "footwear", "rating": 4.5 }

Your chosen template (e.g., List) has specific slots where you want to place this data, such as:

  • Heading – where the main title goes
  • Subheading – where supporting info goes
  • Excerpt – where description goes
  • Image – where the product image goes

Field mapping connects the API data fields to these template slots. In the example above:

  • title (from API) maps to Heading (template)
  • description (from API) maps to Excerpt (template)
  • image_url (from API) maps to Image (template)
  • category (from API) maps to Subheading (template)

How to Map Fields

In the API Press admin, under the Display tab:

  1. Choose your template (e.g., List)
  2. For each template field, you will see a dropdown or input showing available API fields
  3. Select the API field that corresponds to each template slot
  4. Save your mappings

The admin interface will show you:

  • Available API fields from your response (fetched from the configured endpoint)
  • Required fields marked with an asterisk (*)
  • Optional fields that you can leave unmapped
Pro Tip: Preview your API response in the admin to see exactly what field names are available. The field names must match exactly with your API response.

Understanding Nested Fields

Some APIs return nested or hierarchical data. For example:

{ “product”: { “name”: “Sneakers”, “specs”: { “size”: “10”, “color”: “blue” } } }

To access nested fields, use dot notation:

  • product.name accesses the name field inside product
  • product.specs.color accesses the color inside specs

If your API returns an array of multiple levels, you may need to specify the root element first. API Press has a “Root Element” setting to help with this. The Root Element tells API Press where in the response structure to find your data items.

Example: If the API returns { "results": [ { ... }, { ... } ] }, set the Root Element to results to tell API Press to loop through those items.

Using Data Transforms

Transforms allow you to format or modify field values before display. For example, you can:

  • Truncate long text to a specific length
  • Format dates in a specific way
  • Format numbers as currency
  • Change text case (uppercase/lowercase)
  • Add prefixes or suffixes

Available Transforms

truncate:200Cuts text to 200 characters, adds “…” at the end. Change the number to any character limit.

Example: truncate:100

upperConverts text to UPPERCASE.

Input: blue
Output: BLUE

lowerConverts text to lowercase.

Input: Blue
Output: blue

date:Y-m-dFormats dates. Change the format as needed.

Input: 2024-01-15
Output: 2024-01-15
Try: date:m/d/Y for 01/15/2024

number:0Formats numbers. The number specifies decimal places.

Input: 123.456
Output with number:2 123.46

currency:USDFormats as currency. Use your currency code.

Input: 99.99
Output: $99.99

before:https://Adds text before the value.

Input: example.com
Output: https://example.com

after:.jpgAdds text after the value.

Input: image
Output: image.jpg

ensure_prefix:https://Adds prefix only if not already present.

Input: example.com
Output: https://example.com

ensure_suffix:.pngAdds suffix only if not already present.

Input: image.jpg
Output: image.jpg (no change)

join:,Joins array items with a separator. Use a comma or any character.

Input: [“red”, “blue”, “green”]
Output: red, blue, green

How to Apply Transforms

When mapping a field, you can add transforms to modify the value. You can apply multiple transforms to a single field by chaining them together.

Example: To truncate text to 150 characters and then convert to uppercase:

upper | truncate:150

The transforms are applied in order from left to right.

Transform Examples

Use Case Field Transform Result
Display timestamp as date created_at date:M d, Y Jan 15, 2024
Show price with currency price currency:USD $99.99
Make category uppercase category upper ELECTRONICS
Shorten long description description truncate:100 First 100 characters…
Ensure URL has protocol website ensure_prefix:https:// https://example.com
Add file extension image ensure_suffix:.jpg photo.jpg
Convert list to text tags join:, tag1, tag2, tag3

Mapping the List Template Fields

Here’s a detailed guide for mapping each field in the List template:

Heading (Required)

The main title of each item. This field is required. Choose the API field that contains the item’s primary identifier or name.

Examples: titlenameproduct_name

Subheading (Optional)

Secondary text below the heading. Could be a category, author, date, or other detail.

Examples: categoryauthordate | date:M d, Y

Excerpt (Optional)

Description or preview text. Usually a longer piece of text.

Examples: descriptionsummary | truncate:200

Image (Optional)

URL of an image to display. The field should contain a direct URL to an image file.

Examples: image_urlthumbnailphoto

If the field does not contain a complete URL, use transforms to build it:

image_id | before:https://example.com/images/ | after:.jpg

Link URL (Optional)

Where the item links to when clicked. Should be a complete URL starting with http:// or https://.

Examples: urllinkproduct_url

If needed, use transforms to build the URL:

product_id | before:https://example.com/products/ | after:/

Button Label (Optional)

The text displayed on the action button. Common values: “Read More”, “View Details”, “Learn More”, “Buy Now”, “View Profile”.

Examples: button_textaction_label

If your API does not have this field, leave it unmapped and set a static value in the template settings.

Badge (Optional)

A small label or tag in the corner. Often used for status or special labels.

Examples: statustagpriority

Use transforms to format the badge text:

status | upper to show “NEW” or “FEATURED”

Common Mapping Scenarios

Scenario 1: Blog Posts

Heading: title Subheading: author | upper Excerpt: content | truncate:200 Image: featured_image_url Link URL: post_url Button Label: “Read Article” Badge: category

Scenario 2: Product Listings

Heading: product_name Subheading: brand Excerpt: description | truncate:150 Image: product_image Link URL: product_url Button Label: “View Product” Badge: status

Scenario 3: Team Members

Heading: full_name Subheading: job_title | upper Excerpt: bio | truncate:100 Image: profile_photo_url Link URL: profile_url Button Label: “Learn More” Badge: department

Troubleshooting Field Mapping

Field not showing up in the dropdown

Solution: The API response might not have been loaded yet. Click the “Fetch API Data” or “Test Request” button to retrieve the current API response, then refresh the field mapping interface.

Transform not working as expected

Solution: Check that:

  • The transform syntax is correct
  • The API field contains compatible data (e.g., date transforms need date values)
  • Multiple transforms are separated by pipes (|)

Data displaying incorrectly

Solution: Verify that:

  • The correct API field is mapped to each template slot
  • Field names are spelled exactly as they appear in the API response
  • Nested field paths use correct dot notation (e.g., user.name)

Image not displaying

Solution: Check that:

  • The image field contains a complete URL with protocol (https://)
  • The image URL is publicly accessible
  • Use the ensure_prefix:https:// transform if needed

Next Steps

After mapping your fields:

  1. Preview the display to make sure the data appears correctly
  2. Adjust templates and transforms if needed
  3. Move to the next article: Displaying on Your Site to add the API data to your pages