# Conditional query/API call

**URL:** <https://community.dreamfactory.com/t/conditional-query-api-call/717>\
**Category:** REST API\
**Created:** [December 30, 2014, 6:39am UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717 "2014-12-30T06:39:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![liveashish](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/liveashish/32/193_2.png) [@liveashish](https://community.dreamfactory.com/u/liveashish)\
**Post date:** [December 30, 2014, 6:39am UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/1 "2014-12-30T06:39:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benbusse](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/benbusse/32/4_2.png) [@benbusse](https://community.dreamfactory.com/u/benbusse)\
**Post date:** [December 30, 2014, 3:23pm UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/2 "2014-12-30T15:23:41Z")

</div>

> > 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](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:

> **[Demo – How to Make Relationship Queries with DreamFactory’s REST API -...](https://blog.dreamfactory.com/Demo-How-to-Make-Relationship-Queries-with-DreamFactory-s-REST-API/)**
>
> Developers often ask how to query related data with DreamFactory’s REST API. For example, how do you fetch a record and its related children as JSON in a single API call? In this post, we’ll demonstrate related data queries with a real example. Also...

> **[Executing SQL Joins in REST APIs Using DreamFactory - DreamFactory Software-...](https://blog.dreamfactory.com/sql-and-rest-working-with-related-data/)**
>
> As a follow up to our previous blog post about retrieving related data from that REST API, I wanted to dive deeper into the power of the "related records" feature of DreamFactory's database-backed APIs One of the powerful features of SQL databases is...

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](https://github.com/dreamfactorysoftware/dsp-core/wiki/SQL-Stored-Procedures)

---

<div class="post-metadata">

**Author:** ![liveashish](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/liveashish/32/193_2.png) [@liveashish](https://community.dreamfactory.com/u/liveashish)\
**Post date:** [January 5, 2015, 7:20am UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/3 "2015-01-05T07:20:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![benbusse](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/benbusse/32/4_2.png) [@benbusse](https://community.dreamfactory.com/u/benbusse)\
**Post date:** [January 5, 2015, 3:45pm UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/4 "2015-01-05T15:45:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![liveashish](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/liveashish/32/193_2.png) [@liveashish](https://community.dreamfactory.com/u/liveashish)\
**Post date:** [January 5, 2015, 4:23pm UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/5 "2015-01-05T16:23:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![liveashish](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/liveashish/32/193_2.png) [@liveashish](https://community.dreamfactory.com/u/liveashish)\
**Post date:** [January 5, 2015, 4:33pm UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/6 "2015-01-05T16:33:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abhishek\_farkade](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@abhishek\_farkade](https://community.dreamfactory.com/u/abhishek_farkade)\
**Post date:** [April 8, 2015, 5:52am UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/7 "2015-04-08T05:52:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![benbusse](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/benbusse/32/4_2.png) [@benbusse](https://community.dreamfactory.com/u/benbusse)\
**Post date:** [April 8, 2015, 6:47am UTC](https://community.dreamfactory.com/t/conditional-query-api-call/717/8 "2015-04-08T06:47:44Z")

</div>

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