#Calling api through postman is working but not through functions

54 messages · Page 1 of 1 (latest)

meager widget
#

I'm working on project where Appwrite is self-hosted. When I try to retrieve a list of database or any other query is not working I just get:

No response recorded
No logs recorded
An internal curl error has occurred within the executor! Error Msg: Operation timed out

The databases basically are empty

I did try it with postman and used the same Endpoint, API key, Project and it worked but with functions (PHP also tried with Node) is not working. I also created an account in cloud.appwrite.com just to test the code and it worked there also.

Can it be that there is misconfiguration in server side? Any help would be apricated.

Thank you

open schooner
meager widget
open schooner
#

Do you have SSL enabled on your self-hosted instance?

meager widget
open schooner
#

Still not sure what could be the issue. I'm trying to think 😅

meager widget
#

Now I see that I can access also without https only with http ?! Also I have seen that they have two domains config with the same server can that be a problem? I have tried with both domains but get the same results

open schooner
open schooner
#

have you also added a /v1 in your endpoint?
e.g. https://example.appwrite.io/v1

meager widget
open schooner
meager widget
#

Also when I create new API Key and just execute the code/function I have attached in the original post I can see that LAST ACCESSED for that API it stays NEVER

open schooner
#

This is so weird because my executions are failing, but there's no logs at all!

Response: No response recorded
Logs: No logs recorded
Errors: No errors recorded

#
<?php

require_once('vendor/autoload.php');

use Appwrite\Client;
use Appwrite\Services\Databases;

return function($req, $res) {
  $client = new Client();
    
  $client
    ->setEndpoint('https://cloud.appwrite.io/v1')
    ->setProject('[PROJECT-ID]')
    ->setKey('[API-KEY-SECRET]')
  ;

  // You can remove services you don't use
  $databases = new Databases($client);

  $result = $databases->list();

  $res->json([
    'message' => 'Done!',
    'result' => $result
  ]);
};

edit: updated code

#

This code worked for me as expected. This is the output I got:

{"message":"Done!","result":{"total":1,"databases":[{"$id":"64773d2a68be775430cb","name":"test","$createdAt":"2023-06-17T12:27:22.429+00:00","$updatedAt":"2023-06-17T12:27:22.429+00:00"}]}}
#

The only thing I changed after deployment, is the Execute Access in the function settings and I set it to Any.

#

Also, my API key has only the databases.read access scope on it.

#

Here's what I suggest you to try:

#
  1. Make an API key with the scope databases.read
  2. Use the Appwrite CLI to create a new function with appwrite init function, and select PHP as the runtime.
  3. In the index.php file, use the code I sent and deploy your function with appwrite deploy function. Move to the function you just created with arrow keys, and press Space to select it, then hit Enter to deploy it.
  4. Go to the function settings in your appwrite console, and add the Any role to the Execute Access setting.
  5. Execute the function with no payload.
#

Let me know if it works 🙂

meager widget
#

Same, executions are failing! 🙁

I did everything as you said

open schooner
meager widget
#

Yes I know that, I made sure that I followed the order you told me

open schooner
#

Wrong thread, ignore that lol

open schooner
#

and try to execute again

#

that's what I did too

#

maybe the classic trick in the book works LMAO

meager widget
#

Oh man I have been trying this trick for whole week and it didn't work LOL

open schooner
#

also just to be sure, you are using the appwrite cli right?

meager widget
meager widget
#

As I said, I do all the same steps in cloud.appwrite.com and It works as it should. Only when I try in this self-hosted doesn't work

near bear
meager widget
grave wigeon
meager widget
meager widget
grave wigeon
meager widget
# grave wigeon Other API calls from your client app work right?

If I understood your question correctly, yes for example flutter developers they can access the api calls also if I use postman and make a call directly with endpoints it works but when i deploy the function and execute with php sdk or node sdk i dosent work

grave wigeon
grave wigeon
meager widget
#

I change the catch Class to Exception

and got this response

{"message":"Error!","result":"Failed to connect to domainoftheerver.eu port 443 after 130149 ms: Couldn't connect to server"}

grave wigeon
#

Some ways to test and troubleshoot this are to see if a request is success from the server itself and then from the runtime container

meager widget
#

Is this normal for example to work for postman calls etc but not for functions calls

open schooner
grave wigeon
meager widget
# grave wigeon Not really. Usually, this is a firewall problem

I'm still having the same problem. I asked the guy and he told me firewall is disabled also he reconfigred the ssl, nowhttp redirects to https.

Also if a make a function that returns for examle string it works fine $res->json("test), but not these others

grave wigeon
meager widget