REST API Reference

BF Blocks extends the WordPress REST API under the /wp-json/bf-blocks/v1/ namespace.

Authentication

Read endpoints are public. Write and delete endpoints require authentication via:

  • WordPress nonce — pass X-WP-Nonce header. Use wp_create_nonce('wp_rest').
  • Application Password — HTTP Basic auth. Generate in Users → Profile → Application Passwords.

Endpoints

MethodPathDescriptionAuth
GET/wp-json/bf-blocks/v1/blocksList all registered block definitionsNone (public)
GET/wp-json/bf-blocks/v1/blocks/:slugGet a single block definition by slugNone (public)
POST/wp-json/bf-blocks/v1/blocksCreate a new block definitionEditor+ or nonce
PUT/wp-json/bf-blocks/v1/blocks/:slugUpdate an existing block definitionEditor+ or nonce
DELETE/wp-json/bf-blocks/v1/blocks/:slugDelete a block definitionAdministrator
GET/wp-json/bf-blocks/v1/templatesList all templates (built-in + custom)None (public)
POST/wp-json/bf-blocks/v1/exportExport one or more blocks as JSONEditor+ or nonce
POST/wp-json/bf-blocks/v1/importImport block definitions from JSONAdministrator

Example: List All Blocks

fetch('https://yoursite.com/wp-json/bf-blocks/v1/blocks')
  .then(res => res.json())
  .then(blocks => console.log(blocks));

Response:

[
  {
    "id": 1,
    "slug": "bf-blocks/testimonial",
    "name": "Testimonial",
    "icon": "format-quote",
    "category": "theme",
    "fields": [ ... ]
  }
]

Example: Create a Block (Authenticated)

const response = await fetch(
  'https://yoursite.com/wp-json/bf-blocks/v1/blocks',
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-WP-Nonce': wpApiSettings.nonce,
    },
    body: JSON.stringify({
      name: 'My Block',
      fields: [
        { key: 'heading', type: 'text', label: 'Heading' }
      ]
    })
  }
);