## **🧭 Overview**

Search Atlas does not support direct webhook creation for custom PHP websites. This is expected behaviour — the webhook option in the publishing settings is reserved for supported third-party platforms. If you are running a custom PHP backend, you can still publish AI-generated content automatically using one of two integration methods described in this article.

## **⚙️ Choose Your Integration Method**

Before you begin, determine how your PHP site stores content:

- **Database storage** — your site uses MySQL, MariaDB, or another database to store posts and pages.
- **File storage** — your site writes content to flat files such as HTML, Markdown, or JSON files on the server.

Both methods use the **Search Atlas REST API** to retrieve published content. The difference lies in how your PHP script handles and stores the data once it is received.

## **🔑 Step 1 — Generate Your API Key**

1. Log in to Search Atlas, click your **Avatar**, and open **Settings**.
2. Navigate to **API Keys**.
3. Click **Generate New Key** and copy the key to a safe location.
4. Note your **Organisation ID** displayed on the same page — you will need it in later steps.

## **📡 Step 2 — Set Up the PHP Integration Script**

Create a new PHP file on your server, for example **fetch-content.php**. This script will request your published content from the Search Atlas API and store it on your site.

**Base API request structure:**

- Endpoint: **https://api.searchatlas.com/v1/content/published**
- Method: **GET**
- Required headers: **Authorization: Bearer YOUR\_API\_KEY** and **X-Organisation-ID: YOUR\_ORG\_ID**
- Optional query parameter: **?since=TIMESTAMP** to retrieve only content published after a specific date and time.

Your PHP script should perform an HTTP request to this endpoint using **cURL** or a library such as Guzzle, then decode the JSON response and process each content item.

## **🗄️ Step 3A — Store Content in a Database**

If your PHP site uses a database, follow these steps after retrieving the API response:

1. Connect to your database using PDO or MySQLi.
2. For each content item in the response, check whether a record with the same **content\_id** already exists in your posts table.
3. If the record exists, run an **UPDATE** statement to refresh the title, body, slug, and updated timestamp.
4. If the record does not exist, run an **INSERT** statement to create a new row.
5. Map the following API response fields to your table columns: **title**, **body\_html**, **slug**, **meta\_description**, **published\_at**, and **content\_id**.

## **📁 Step 3B — Store Content as Flat Files**

If your PHP site uses file-based storage, follow these steps after retrieving the API response:

1. Define a target directory on your server where content files will be saved, for example **/var/www/html/content/**.
2. For each content item in the response, construct a file name using the **slug** field and your preferred extension, such as **my-article-slug.html**.
3. Write the **body\_html** value to the file using **file\_put\_contents()**. This will create the file if it does not exist or overwrite it if it does.
4. Optionally, write a companion JSON file for each piece of content containing the title, meta description, and published date for use by your templating layer.

## **⏱️ Step 4 — Automate With a Cron Job**

Because webhooks are not available for custom PHP backends, you will use a scheduled cron job to poll the API at regular intervals and keep your site up to date.

1. Open your server's crontab by running **crontab -e** in the terminal.
2. Add a new line to run your script on your preferred schedule. For example, to run every 15 minutes use: **\*/15 \* \* \* \* php /var/www/html/fetch-content.php**
3. Save the crontab. Your server will now automatically check for new or updated content and publish it to your site.
4. To retrieve only new content on each run, store the timestamp of the last successful fetch and pass it as the **since** query parameter in each API request.

## **✅ Step 5 — Test the Integration**

1. Publish a test article from the Search Atlas content editor.
2. Manually run your PHP script from the terminal to confirm it fetches the article without errors.
3. Verify the article appears in your database table or file directory as expected.
4. Check that the cron job runs on schedule by reviewing your server logs after the next scheduled interval.

## **🚫 Common Issues and Fixes**

- **401 Unauthorised error** — Confirm your API key is correct and has not expired. Regenerate it in Settings if needed.
- **Empty response from API** — Ensure at least one article has been published in Search Atlas and that your Organisation ID is correct.
- **Cron job not running** — Verify the PHP binary path in your cron command by running **which php** in the terminal and updating the crontab accordingly.
- **Duplicate content in database** — Confirm your upsert logic is checking against the **content\_id** field, not the title or slug, which may change.

## **💬 Need More Help?**

If you need further assistance, open the chat widget in the bottom-right corner of the platform and type **human teammate** to be connected with a member of our team.