|

Create Custom D365 Business Central API in One Click!

Have you ever been asked to create APIs for dozens (or even hundreds!) of Business Central tables? If you have, you know the pain of manually writing repetitive AL code for each table, defining fields, setting properties, and maintaining consistency across all your API pages.

Well, I recently faced this exact challenge when a client asked me to create APIs for more than 100 Business Central tables. The thought of manually coding each one was daunting—until I had an idea that changed everything.

The Problem: API Development at Scale

Creating custom APIs in Business Central typically involves:

  • Writing boilerplate AL code for each API page
  • Manually listing all table fields
  • Converting field names to camelCase for proper API formatting
  • Setting up API metadata (version, publisher, group, etc.)
  • Ensuring consistency across all API definitions

For one or two tables, this is manageable. But for 100+ tables? That’s weeks of tedious, error-prone work.

The Solution: An API Generator Page

Instead of writing each API manually, I built a Business Central page that generates the entire API code automatically. This tool runs directly within BC and creates production-ready API page code based on just a few inputs.

How It Works

The generator is incredibly simple to use:

  1. Enter the Table ID – The tool automatically fetches all field metadata
  2. Configure API Settings – Set your API version, publisher, and group
  3. Click “Generate API” – Get complete, copy-paste-ready AL code

The tool leverages Business Central’s built-in Field record and metadata capabilities to dynamically inspect any table and generate properly formatted API code. It saved me 99% of the time I would have spent manually coding!

Key Features

🎯 Automatic Field Generation

The generator loops through all table fields and creates properly formatted API field definitions with:

  • camelCase field names (following OData conventions)
  • Correct AL syntax with escaped special characters
  • Caption and ToolTip properties

🔧 Full Customization

You have complete control over:

  • API Version (e.g., v2.0)
  • API Publisher (your organization name)
  • API Group (categorization)
  • Entity names and captions
  • CRUD permissions (Insert, Modify, Delete)
  • OData key fields

💡 Smart Field Handling

The ToCamelCase function strips out special characters and converts field names to proper API format, handling edge cases like:

  • Spaces → removed and capitalized
  • Special characters ($, %, #, etc.) → removed
  • Consistent lowercase first letter

⚡ Instant Results

Instead of hours of typing, you get production-ready code in seconds that you can immediately embed into your AL project.

Real-World Impact

This tool transformed my development workflow:

  • Time Savings: What would have taken weeks took just hours
  • Consistency: Every API follows the same pattern and standards
  • Fewer Errors: No typos or missed fields
  • Easy Maintenance: Need to update an API? Just regenerate it

When to Use This Tool

This API generator is perfect for:

  • Bulk API creation projects
  • Rapid prototyping and POCs
  • Standardizing API patterns across your organization
  • Creating integration endpoints quickly
  • Learning API development in Business Central

The Complete Code

Below is the full AL code for the API Generator page. You can add this to your Business Central extension project and start generating APIs immediately:

How the Code Works

Let me break down the key components:

1. The Field Record System

al

This uses Business Central’s built-in Field record to dynamically read all field metadata from any table. The Field table is a system table that contains information about every field in every table in BC.

2. Automatic Entity Name Generation

al

When you select a table, the tool automatically generates proper entity names following OData conventions (singular for entity, plural for entity set).

3. Dynamic Code Generation

The GenerateAPI action builds the complete API page code string by string, using the Type Helper codeunit for proper line breaks and formatting. This ensures the generated code is properly formatted and ready to use.

4. The ToCamelCase Function

This is the heart of proper API formatting. It:

  • Strips out all special characters that aren’t valid in API field names
  • Converts spaces to camelCase (e.g., “Customer Name” becomes “customerName”)
  • Ensures compliance with OData naming standards

5. Field Loop Generation

al

This loop processes every field in the table, generating a complete field definition with caption and tooltip for each one. It even filters out problematic fields like CRM coupling fields.

Tips for Using the Generator

  1. Review Generated Code: While the generator produces valid code, always review it before deploying to ensure it meets your specific requirements.
  2. Customize as Needed: You can edit the generated code in the text field before copying it to your project.
  3. Adjust Page ID: Remember to change the page ID (60101 in the generated code) to match your numbering scheme.
  4. Security: Don’t forget to set up proper permissions for your API pages in production.
  5. Testing: Always test your generated APIs with tools like Postman before using them in production integrations.

Conclusion

Building custom APIs in Business Central doesn’t have to be a time-consuming manual process. With this API Generator tool, you can:

  • Save 99% of your development time on API creation
  • Ensure consistency across all your API endpoints
  • Reduce errors from manual typing
  • Focus on business logic instead of boilerplate code

Whether you’re building a single API or a hundred, this tool transforms a tedious task into a one-click operation. Give it a try in your next Business Central integration project—you’ll wonder how you ever lived without it!


Have you faced similar challenges with bulk API development? Share your experiences in the comments below!

And if you found this tool useful, feel free to customize it for your organization and share it with your team. Happy coding! 💻✨

Leave a Reply

Your email address will not be published. Required fields are marked *