Page 1 of 2

Calling an Api Express from server code

Posted: Sat Apr 23, 2016 12:44 am
by sdanigo

Hi,
I'd like to call an Api Express made connexion to a mySql database from a server side javascript code.
What is the correct syntax ?
My goal is to retreive a set of data from an external database and proceed that set in a server code script.
Thanks

Sylvain


Calling an Api Express from server code

Posted: Sat Apr 23, 2016 5:41 am
by Galyna Abramovych

Hello Sylvian,

Thank you for contacting Appery.io support!

Please have a look at this tutorial: https://devcenter.appery.io/tutorials...

Mind, that you can't call API Express service as Appery.io DB collection. Server code won't find that collection.
Please call API Express service in the server code as a simple XMLHttpRequest: https://devcenter.appery.io/documenta...

Also, you have to make available our application servers DNS: https://devcenter.appery.io/documenta...


Calling an Api Express from server code

Posted: Thu Aug 04, 2016 8:25 pm
by Andrew6784445

Galyna,

I have created an API Express service that connects to MySQL. The service works when tested in API Express AND works directly in my app.

I would like the service to run as Server Code but it does not work. No errors occur. Could you please elaborate on "making our application servers DNS", and any other specifics for calling API Express services from Server Code?

Also, your links are not pointing to anything specific, could you please revise.

Thanks so much,

Andrew


Calling an Api Express from server code

Posted: Thu Aug 04, 2016 9:01 pm
by Illya Stepanov

Hi Andrew -

[quote:]
I would like the service to run as Server Code but it does not work.
[/quote]

Please elaborate what do you mean here?


Calling an Api Express from server code

Posted: Thu Aug 04, 2016 10:10 pm
by Andrew6784445

No Errors. The Service is an Update Query.

Here is the Server Code call:

XHR.send("PUT","https://api.appery.io/rest/1/apiexpre...", {
"headers": {
"apiKey":"xxxxx",
"pUserID": "1",
"pPasscode" : "abcdef",
}
});

The API Express Query is: (BTW-this works when testing in API Express and when connecting API Express Service directly to my app):

UPDATE tblUsers
SET ResetCode = :pPasscode
WHERE UserID = :pUserID

In short, I am attempting to use the SendGrid example for Password Resets using a MySQL Backend in API Express.

Thanks for your help,

Andrew


Calling an Api Express from server code

Posted: Mon Aug 08, 2016 10:05 am
by Serhii Kulibaba

Hello Andrew,

Please check XHR2 method of the Server Code for that issue: https://docs.appery.io/reference#serv...


Calling an Api Express from server code

Posted: Mon Aug 08, 2016 5:17 pm
by Andrew6784445

I changed the Server Code to the following but it still doesn't update the record:

var XHRResponse = XHR2.send("PUT","https://api.appery.io/rest/1/apiexpre...", {
"headers": {
"X-Appery-Api-Express-Api-Key" : "xxxxx",
"pUserID": "1",
"pPasscode" : "abcdef"
}

Code: Select all

 }); 

If I test the Service from My APP it works using these same Header parameters. Is there something else I am missing when calling from Server Code? No error occurs, it just doesn't do the update.

-Andrew


Calling an Api Express from server code

Posted: Tue Aug 09, 2016 9:14 am
by Serhii Kulibaba

It looks like you send "pUserID" and "pPasscode" as headers instead of sending them as parameters. Please look at the link above to get an example of usage these parameters, e.g.:

prevar XHRResponse = XHR2.send("PUT", "https://api.appery.io/rest/1/apiexpress/api/svcLogin/SetPasscode", {
"parameters": {
"pUserID": "1",
"pPasscode" : "abcdef"
},
"headers": {
"X-Appery-Api-Express-Api-Key" : "xxxxx"
}
});/pre


Calling an Api Express from server code

Posted: Tue Aug 09, 2016 1:47 pm
by Andrew6784445

Sergiy,

Thanks for the reply. I have updated my APIExpress Service to accept the query parameters as parameters instead of headers. When tested in API Express it works fine. When calling from Server Code using the following code I get no errors but also continue to not see results. Is there some sort of security that prevents an update query from being called by Server Code?

(Here is my revised code copied and pasted-except for API Key of course)
var XHRResponse = XHR2.send("PUT", "https://api.appery.io/rest/1/apiexpre...", {

"parameters": {
"pUserID": "1",
"pPasscode": "abcdef"
},

"headers": {
"X-Appery-Api-Express-Api-Key": "xxxxxx"

}
});


Calling an Api Express from server code

Posted: Fri Aug 12, 2016 5:58 am
by Serhii Kulibaba

You have to read a response of that API Express call.
Please look at this example how to do it: https://docs.appery.io/reference#sect...