Forum in maintenance, we will back soon 🙂
[Solved] Error making tools in WordPress
I've applied your PHP backend template and frontend template in the "Turn WordPress into SaaS" course. I've also followed your API creation course to develop an API using the same templates and attempted to connect it to WordPress. However, I'm encountering errors.
I'm finding it difficult to determine whether this issue arises from the inability to connect to the API in WordPress, or if it's a connection issue between the frontend and PHP code.
Could you provide a frontend example for the /health endpoint from your provided API template?
I wrote tool definition code snippet as follows:
// Tool Configuration
$customHealthToolConfig = [
'ENABLE_LOGGING' => false,
'CUSTOM_TOOL_ID' => 1,
'AUTH_REQUIRED' => true,
'POINTS_REQUIRED' => 0,
'ENDPOINT_PATH' => '/health',
'TOOL_NAME' => "Health Check",
'EXPECTED_PARAMS' => [
]
];
custom_lws_tool_setup('custom_tool_health', $customHealthToolConfig);
Please make sure the API endpoint returns a response in the following structure:
return { "success": True, "message": "done", "result": response }
Next, we can troubleshoot this together.
step 1: we will check that the API is working
step 2: we will connect WordPress with the API and test without the UI
step 3: integrate the UI.
I will publish a new lecture in the course showing this step by step, but for now, let's try to solve your problem; please make sure the response is as I mentioned and the API is working so we can continue.
Sir, I made my API (/example) endpoint to return a response just like the image. It worked perfectly.
Here is the code for the endpoint.
@router.get("/example") async def example_endpoint(): response = {"message": "This is an example endpoint"} return { "success": True, "message": "done", "result": response }
@husein , The endpoint is working perfectly.
I'm facing difficulty connecting the API endpoint with WordPress.
I tried applying the PHP code for API calls, provided from a lecture, to WordPress. However, I'm unsure how to connect this code with the frontend. I attempted to follow the example of frontend code provided from lecture, but encountered an error.
I'm struggling to determine whether this error stems from the PHP code I applied for API calls, leading to a failure in connecting the API with WordPress, or if the issue lies in the connection between the PHP code and the frontend code.
@junho no worries, can you please share the full endpoint URL, So I can test from my side
@junho I just updated the course with a step by step guide on how to integrate Python with WordPress:
Update: Full Example From Python To UI. - LearnWithHasan
Please check, and make sure you did the same, and if the problem persists. I will check my self, dont worry