Skip links

CakePHP Integration Guide for Blog Botz

CakePHP Integration Guide for Blog Botz

Follow this step-by-step guide to integrate Blog Botz with your CakePHP website and automatically publish blogs.

Step 1: Set Up Your Blog Botz Account

Visit Blog Botz and log in to your account. Set up your blog schedules, preferences, and ensure your blogs are ready for auto-publishing.

Step 2: Generate Webhook URL in Blog Botz

In your Blog Botz dashboard, navigate to Settings and select API & Webhook Integration. Generate a Webhook URL, and copy it for use in your CakePHP site configuration.

Step 3: Set Up Webhooks in CakePHP

Create a new controller in CakePHP to handle the incoming data from Blog Botz.

Create the Controller:

src/Controller/BlogBotzController.php

Insert the following code in BlogBotzController.php:



namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Http\Exception\BadRequestException;

class BlogBotzController extends AppController {
    public function webhook() {
        $this->autoRender = false; // No need for a view
        
        if ($this->request->is('post')) {
            $data = $this->request->getData();
            
            // Validate and process the incoming request
            if (!empty($data)) {
                $this->loadModel('Blogs');
                $blog = $this->Blogs->newEntity($data);
                if ($this->Blogs->save($blog)) {
                    return $this->response->withStatus(200);
                } else {
                    throw new BadRequestException('Unable to save blog data.');
                }
            }
        }
        throw new BadRequestException('Invalid request.');
    }
}
            

Step 4: Update Routes

Add the following route to config/routes.php to connect the webhook URL:

$routes->connect('/blog-botz/webhook', ['controller' => 'BlogBotz', 'action' => 'webhook']);

Step 5: Verify Webhook Reception

After setting up the controller and route, test the webhook reception by adding the webhook URL to Blog Botz:

https://your-cakephp-site.com/blog-botz/webhook

Step 6: Automate Blog Creation

Ensure your CakePHP application can receive and process the blog data sent from Blog Botz. Customize the webhook() method to fit your application’s requirements, such as adding categories, tags, or scheduling posts.

If you need any further assistance, feel free to reach out to the Blog Botz support team.

Automatic CakePHP Blog maker
Connect Your CRM / Website

Troubleshooting Tips for CakePHP Integration

Resolve common issues with integrating Blog Botz and CakePHP using these quick troubleshooting tips:

1. Webhook Not Triggering

Check URL: Ensure the webhook URL in Blog Botz matches your CakePHP route.

HTTPS Requirement: Use HTTPS for the webhook URL.

Test Endpoint: Use tools like Webhook Tester to ensure your endpoint is receiving data.

2. 400 Bad Request Error

Content-Type: Verify Blog Botz is sending data as application/json.

POST Method: Ensure your webhook method is expecting a POST request.

3. Database Not Updating

Model Issues: Ensure the Blogs model is set up correctly to receive the data.

Debugging: Log incoming data with debug($this->request->getData()) to verify it matches your model.

4. No Logs or Response

Enable Logging: Add log('Webhook triggered', 'debug'); to ensure the webhook is triggered.

Permissions: Ensure the route and controller are publicly accessible without authentication.

5. Security Issues

CSRF Protection: Disable CSRF for the webhook:

$this->getEventManager()->off($this->Csrf);

Token Validation: Require an API key and validate it in the webhook() method if necessary.

6. 404 Error for Route

Check Routes: Ensure the route is defined correctly in config/routes.php.

Clear Cache: Run bin/cake cache clear_all to clear cached routes.

7. Handling Large Payloads

Increase Limits: Update post_max_size and upload_max_filesize in php.ini to handle large blog content.