Skip to content

Forum in maintenance, we will back soon 🙂

Notifications
Clear all

API Template

81 Posts
3 Users
15 Reactions
248 Views
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@admin thank you for your answer. I am talking only from the saas course and its codes - not the new course. I will look into it with the ajax testing. I hope this will solve the problem. Thank you for your patience.

 
Posted : 03/02/2024 3:22 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

@dari-dar no worries friend, we are here to help. Please test and make sure the backend function is working. so we can work on the UI together 🙂

 
Posted : 03/03/2024 9:43 am
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@admin I tried with ajax. The test-tool functions, I get success - see screenshot, but the custom tool has no success. I dont understand why.


 i looked, that i only changed what is allowed to change in the codes from you I used and I cant find the error:
the Tool-Code:
// SEO tool
$seo_tool_config = [
'ENABLE_LOGGING' => false,
'CUSTOM_TOOL_ID' => 70,
'AUTH_REQUIRED' => false,
'POINTS_REQUIRED' => 3,
'ENDPOINT_PATH' => 'seo/google_keyw_rank',
'TOOL_NAME' => "SEO Rank",
'EXPECTED_PARAMS' => [
'keyword' => [
'type' => 'string',
'error_message' => 'keyword not provided.',
]
]
];

custom_lws_tool_setup('custom_tool_seo_test', $seo_tool_config);

 

 

here the only thing i changed in the function used by all tools snippet:

function lwh_get_api_key() {
return 'abcdefg'; //
}

function get_custom_tools_api_base_url() {
return "https://hastemp-3137e0496156.herokuapp.com/";
}

 

in the generic function i didnt change a thing. Did I forget something? Do i have to change something here?:
// Ensure configuration keys exist and assign default values
$ENABLE_LOGGING = array_key_exists('ENABLE_LOGGING', $tool_config) ? $tool_config['ENABLE_LOGGING'] : true;
$CUSTOM_TOOL_ID = array_key_exists('CUSTOM_TOOL_ID', $tool_config) ? $tool_config['CUSTOM_TOOL_ID'] : 0;
$AUTH_REQUIRED = array_key_exists('AUTH_REQUIRED', $tool_config) ? $tool_config['AUTH_REQUIRED'] : false;
$POINTS_REQUIRED = array_key_exists('POINTS_REQUIRED', $tool_config) ? $tool_config['POINTS_REQUIRED'] : 0;
$ENDPOINT_PATH = array_key_exists('ENDPOINT_PATH', $tool_config) ? $tool_config['ENDPOINT_PATH'] : '';
$TOOL_NAME = array_key_exists('TOOL_NAME', $tool_config) ? $tool_config['TOOL_NAME'] : 'Default Tool';
$EXPECTED_PARAMS = array_key_exists('EXPECTED_PARAMS', $tool_config) ? $tool_config['EXPECTED_PARAMS'] : [];

 
Posted : 03/03/2024 11:20 am
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@dari-dar when posting code please use the code icon (<>) above. It keeps the formatting of the code to make it easier to read.

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 03/03/2024 4:04 pm
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@ssadvisor ok. Didn't know. Thank you for your advice.

 
Posted : 03/03/2024 6:56 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

@dari-dar, if this is a test website, please send me temporary credentials, I will try to check

 
Posted : 03/05/2024 11:33 am
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@admin do you have an email I can give you admin access to?

I created an account with an email of mine for you. I wrote Access-Data in Discord for https://dari-test.um-web.de/wp-admin

 
Posted : 03/05/2024 9:59 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

@dari-dar what do you mean by I wrote Access-Data in Discord

anyway, here is my email: hasan@learnwithhasan.com

 
Posted : 03/06/2024 12:54 pm
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

Hello @admin, I just created an account for you. You should have an email for setting a password on https://dari-test.um-web.de/

I couldn answer earlier. I thought I could write to you in on Discord server, but didnt function.

 
Posted : 03/14/2024 8:59 am
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@admin did you have possibility to look in my websites codes? I send you the login-data on your email.

 
Posted : 03/16/2024 7:24 am
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

Finally, I discovered the problem: it is not your fault. It is mine. Everything is working perfectly, but the response coming from your API should have the following JSON structure:

{
  "success": true,
  "message": "Generated Titles Successfully",
  "result": [
    ....
  ]
}

Your api returns:

{
  "results": [
    ....
  ]
}

Again, I am sorry I didn't clarify that in the course; it took me 2 hours of testing on your site to discover this. 

Can you please update your API to return the same structure? Adding success and message in your response. Then we can check and continue debugging if it doesn't work.

 

And I will be working on a more generic approach so you can return any structure you want.

 
Posted : 03/16/2024 1:15 pm
SSAdvisor reacted
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@admin thank you for your response. I changed the code for my api:

@router.get("/seo/google_keyw_rank")
async def root(keyword: str, num_results: int = 10, n_pages: int = 1):
    try:
        results = []
        counter = 0
        for page in range(0, n_pages):
            url = f"https://www.google.com/search?q={keyword}&start={page * 10}"
            headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
            }
            response = requests.get(url, headers=headers)
            soup = BeautifulSoup(response.content, "html.parser")
            search = soup.find_all("div", class_="tF2Cxc")

            for h in search:
                if counter == num_results:
                    break
                counter += 1
                title = h.find("h3").text
                link = h.find("a")["href"]
                rank = counter
                htitles = extract_h_titles(link)

                results.append(
                    {
                        "title": title,
                        "url": link,
                        "rank": rank,
                        "htitles": htitles,
                    }
                )

        if not results:
            raise HTTPException(status_code=404, detail="No results found")

        return {"success": True, 
                "message": "Generated Titles Successfully", 
                "result": results
                }

    except Exception as e:
        return {"success": False,
                "message": str(e),
                "result": []
                }

 

but unfortunately i still get this when i try:

Test Your AJAX Function
Enter your WordPress website URL:
 https://dari-test.um-web.de/ 
Enter the AJAX function name:
custom_tool_seo_test
{
  "success": false,
  "message": "Operation failed",
  "data": null
}

 

i am still looking and trying out to find the problem.

 
Posted : 03/16/2024 3:31 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

@dari-dar Thanks for the update; now I can continue debugging and checking.

Can I log in again to your site to continue testing?

 
Posted : 03/17/2024 3:59 pm
DariDar
(@dari-dar)
Posts: 47
Trusted Member Customer Registered
Topic starter
 

@admin yes of course. Thank you very much!

 
Posted : 03/17/2024 7:32 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

@dari-dar I just tested it on my end, and it is working. Here are some screenshots:


 

 

 
Posted : 03/18/2024 2:37 pm
Page 4 / 6
Share:
[the_ad_group id="312"]