Conditional query/API call


#1

I want to make a conditional query/API call.

  1. For example, in a login module I want to call the API and check if the username and password provided by the user is true against the DB or not. If its true, then the user logs.

  2. Is there a way that I can make relational query as well? Any example will be appreciated.


#2
  1. For example, in a login module I want to call the API and check if the username and password provided by the user is true against the DB or not. If its true, then the user logs.

DreamFactory validates user name and password on the login API call, so you don’t need to write logic to do this. Make sure to pass in all the correct parameters to authenticate and get a session. Here’s a login cURL example at the top of this page https://github.com/dreamfactorysoftware/dsp-core/wiki/cURL-Examples

  1. Is there a way that I can make relational query as well? Any example will be appreciated.

Yes, you can fetch parent plus child records (1:M) or fetch records from two sibling tables via an intermediary junction table (M:M) in a single API call. To do that, pass in the correct associative key in the related parameter in the API call itself. You can test this in the API Docs interface in the admin console. Examples are below:

Note that you can also use stored procedures if you have more complex queries that need to join more than two tables. Stored procedures are callable by the API. Examples of that are here:

https://github.com/dreamfactorysoftware/dsp-core/wiki/SQL-Stored-Procedures


#3

Thanks for the login API. Can I use user’s phone number instead of email to validate? If yes, then how do I that?


#4

Currently you can’t use phone number as a user name. However, you will be able to that in the 2.0 release coming up in late March.


#5

Alright, I am using email for now. But while using getRecordsByFilter() API with email id, I am getting a response like this:

{
"error": [{
    "context": null,
    "message": "Failed to retrieve records from 'my-data'.\nCDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@xyz.com LIMIT 1000' at line 3",
    "code": 500
}]

}

And this is my code,

var username = "email@xyz.com" ;
$http.get('https://dsp-something.cloud.dreamfactory.com:443/rest/db/my-data?filter=email%3D'+username+'&fields=*', header).success(function ( response ) {
                                   console.log(username);
                                });

What’s wrong with my request?


#6

Alright, I fixed it. I put "" around the mail id and its working fine.


#7

When is 2.0 going be released ? Please let me know. We are looking to use “Phone Number as a User name”.


#8

We are pushing hard for a 2.0 beta release in May and production release around the end of June.