Skip to content

Forum in maintenance, we will back soon 🙂

Error making tools ...
 
Notifications
Clear all

[Solved] Error making tools in WordPress

12 Posts
3 Users
5 Reactions
142 Views
(@junho)
Posts: 9
Member
Topic starter
 

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);

This topic was modified 6 months ago by Junho
 
Posted : 03/30/2024 2:48 am
Hasan Aboul Hasan
(@admin)
Posts: 1219
Member Admin
 

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.

 
Posted : 03/30/2024 9:29 am
(@junho)
Posts: 9
Member
Topic starter
 

@admin

api response

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
    }

 

 
Posted : 03/31/2024 4:04 am
(@husein)
Posts: 484
Member Moderator
 

@junho, is the first endpoint you created still giving you errors?

 
Posted : 03/31/2024 9:04 am
(@junho)
Posts: 9
Member
Topic starter
 

@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.

 
Posted : 03/31/2024 2:22 pm
Hasan Aboul Hasan
(@admin)
Posts: 1219
Member Admin
 

@junho no worries, can you please share the full endpoint URL, So I can test from my side

 
Posted : 03/31/2024 4:50 pm
(@junho)
Posts: 9
Member
Topic starter
 

@admin Sir following is the api's URL :

api.laboratory.co.kr

/customdocs >> for whitelisted url

 

 
Posted : 03/31/2024 5:58 pm
Hasan Aboul Hasan
(@admin)
Posts: 1219
Member Admin
 

@junho Thanks, API key please

 
Posted : 04/02/2024 10:04 am
(@junho)
Posts: 9
Member
Topic starter
 

@admin The API key is 1234.

 
Posted : 04/02/2024 10:52 am
Hasan Aboul Hasan
(@admin)
Posts: 1219
Member Admin
 

@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

 
Posted : 04/03/2024 11:14 am
SSAdvisor reacted
(@junho)
Posts: 9
Member
Topic starter
 

@admin I really appreciate for your help sir. Finally made it work! 👍 

 

제목 없음
 
Posted : 04/03/2024 12:24 pm
Hasan Aboul Hasan
(@admin)
Posts: 1219
Member Admin
 

@junho Great! Now try to apply on your own APIs 🙂

 
Posted : 04/04/2024 11:01 am
Share: