Error in calling the API from a Cordova application

Hello,

When I build my application with cordova, a js script that starts when the page is loaded must execute the call from the backendless api but it is still an error that is issued, as shown below:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script src="//api.backendless.com/sdk/js/latest/backendless.min.js"></script>
<script type="text/javascript">

	$(document).ready(function() {
		
		$('#BtnBloLdId').hide();
		
		$('#BtnBloLxId').hide();
		
		$('#H3YeResLdId').hide();
		
		$('#H3YeResLxId').hide();
	
		var APP_ID = 'XXXXXXXX-XXXX-XXXX-FF08-XXXXXXXXXXXX';
		var API_KEY = 'XXXXXXXX-XXXX-XXXX-FFE1-AXXXXXXXXXX';


		Backendless.serverURL = 'https://api.backendless.com';
		Backendless.initApp(APP_ID, API_KEY);
		
		var profilStorage = Backendless.Data.of( "Profil" );
		var queryBuilder = Backendless.DataQueryBuilder.create();
	
		queryBuilder.setWhereClause( "mobile = 0645331012" );

		profilStorage.find( queryBuilder )
		.then( function( profilArray ) {
			
			alert(profilArray.length);
			
			if (profilArray.length == '0') {
				
				$('#BtnBloLdId').show();
		
				$('#H3YeResLdId').show();
				
			} else {
			
				$('#BtnBloLxId').show();
				
				$('#H3YeResLxId').show();
				
			}
		});
	});
&lt;/script&gt;

The white list of cordova is enabled on all domains in config.xml:

<universal-links> <host name="api.backendless.com" scheme="https" /> </universal-links>

The result is always the same no response, what to do?

Hi Franck,

Try the following:

  1. add a “.catch” method as described in the doc:
    https://backendless.com/docs/js/doc.html#shared_error_handling
  2. your “whereClause” might need some tweaking if the data type of the “mobile” column is string. In that case, it should look like this (notice the single quotes around the value):

mobile = ‘0645331012’

hello Mark,
I added the “.catch” method as described in the link documentation below, but it has not changed anything?


https://backendless.com/docs/js/doc.html#shared_error_handling

I do not know if you understood me because I explain that my application cordova is built in apk, access to the api launch in server mode on the browser works perfectly as in emulation but when it is built in apk, it does not work!

I would like to know why?
And if this comes from backendless and its security or cordova that blocks any application access built in apk?

Thank you

Hi Franck,

Adding the catch method will not change a lot, except, if there is a problem, you’d be able to handle it (perhaps display a message).

I assume my suggestion about the where clause was not relevant?

If there is a difference in the runtime between an emulator and a device, I would recommend creating a very simple app which does only one API call and see if it works. This would validate whether there is a general configuration issue from the backendless perspective.

Regards,
Mark