Flutter API service call error

Mission: SERVERLESS 101
Task: Invoke the API Service using generated client SDK

Flutter app initializes and runs, but both the ‘getItems’ and ‘purchase’ API calls return error:
BackendlessException: Illegal request-target: Invalid input ‘[’, expected segment, ‘/’, ‘?’ or ‘EOI’ (line 1, column 82), code = 0
Maybe the cartName (cart = ‘MyCart’) is not being converted into the List ‘parameters’ that these two calls want?

The code:
static Future getItems(String cartName) async {
// final parameters = cartName;
final parameters = [cartName];

return await Backendless.customService.invoke(_serviceName, "getItems", parameters).onError((error,
    stackTrace) {print('getItems error: $error');});

} // getItems

static Future purchase(String cartName) {
// final parameters = cartName;
final parameters = [cartName];

return Backendless.customService.invoke(_serviceName, "purchase", parameters).onError((error,
    stackTrace) {print('purchase error: $error');});

} // purchase

Complete app is at:

Hello @Jim_Austin

What SDK do you use?

Since I’m working with Flutter I chose the Flutter SDK … didn’t realize I could use any of the other language SDKs.

Sorry, but I was unable to reproduce your error.
I have one question.
You commented the following lines:
// final parameters = cartName; ?

This is the correct signature that is generated automatically:

class Variables {

    static final _serviceName = "Variables";

    static Future<dynamic> postVariables(String first, String second) {
		final parameters = {"first": first, "second": second};

        return Backendless.customService.invoke(_serviceName, "postVariables", parameters);
    }

    static Future<dynamic> getItems(String item) {
		final parameters = item;

        return Backendless.customService.invoke(_serviceName, "getItems", parameters);
    }

}

Best Regards, Nikita.

Nikita,
I’m completely confused; the Flutter SDK downloaded to me (class CodelessShoppingCartService – see below) is completely different from the “correct signature” (class Variables) you posted above. I note the API service has six functions (getInstructions, etc.) whereas class Variables has just two. What am I missing?

I changed the parameter type because all of the parameter calls are type List< Object > whereas the parameter type defs are simple variables (string or Map). This type mismatch causes the IDE error
“The argument type ‘String’ can’t be assigned to the parameter type ‘List’.”

You said you are “unable to reproduce your error”; is that by running the complete app posted at
CodelessShoppingCartService.zip - Google Drive ?
Jim

Note: the Flutter SDK download also includes a main function that has to be enhanced to call the four functions needed to complete this task.

import ‘package:backendless_sdk/backendless_sdk.dart’;
class CodelessShoppingCartService {
static final _serviceName = “CodelessShoppingCartService”;

static Future<dynamic> getInstructions() {
	final parameters = Map();
    return Backendless.customService.invoke(_serviceName, "getInstructions", parameters);
}

static Future<dynamic> getItems(String cartName) {
	final parameters = cartName;
    return Backendless.customService.invoke(_serviceName, "getItems", parameters);
}

static Future<dynamic> purchase(String cartName) {
	final parameters = cartName;
    return Backendless.customService.invoke(_serviceName, "purchase", parameters);
}

static Future<dynamic> addItem(String cartName, Object item) {
	final parameters = {"cartName": cartName, "item": item};
    return Backendless.customService.invoke(_serviceName, "addItem", parameters);
}

static Future<dynamic> deleteItem(String cartName, String productName) {
	final parameters = {"cartName": cartName, "productName": productName};
    return Backendless.customService.invoke(_serviceName, "deleteItem", parameters);
}

static Future<dynamic> setQuantity(String cartName, String productName, double quantity) {
	final parameters = {"cartName": cartName, "productName": productName, "quantity": quantity};
    return Backendless.customService.invoke(_serviceName, "setQuantity", parameters);
}

static Future<dynamic> Items(String cartName, List<dynamic> items) {
	final parameters = {"cartName": cartName, "items": items};
    return Backendless.customService.invoke(_serviceName, "Items", parameters);
}

}

Hello, @Jim_Austin.

Yes, in the example you share as a zip archive, the code signature is incorrect, of course it won’t work:

In the example code you provided at the bottom of the post, everything looks correct.
I don’t understand what problem you are facing.

I just generated a CodelessShoppingCartService and everything works fine.

Best Regards, Nikita.

Nikita,

  1. If by “code signature” (referring to the “zip archive”) you mean the app id, and android and IOS keys, they are correct: same as in the download and in the console. The Backendless.initApp call looks different because the download has backendless_sdk: ^0.1.1, where the parameter calls were positional; in the “zip archive” with backendless_sdk: ^7.1.8, Backendless.initAp
    calls are optional, thus named.

  2. As I said in the first post (12/21), the “zip archive” version runs, but returns errors on the ‘getItems’ and ‘purchase’ API calls: BackendlessException: Illegal request-target: Invalid input ‘[’, expected segment, ‘/’, ‘?’ or ‘EOI’ (line 1, column 82), code = 0.

  3. The “example code” in my previous post is the CodelessShoppingCartService downloaded code. It can’t run because of the type mismatch between the ‘parameter’ type definitions (simple) in each function, and the ‘parameter’ call type of List. This cause the IDE error “The argument type ‘String’ can’t be assigned to the parameter type ‘List’.” as mentioned in my 12/23 post. (IDE screen in attached parameters error.jpeg).

  4. The main function in the download never calls the functions in class CodelessShoppingCartService so the download code can’t run as is. (IDE screen attached)

The “zip archive” left for you is my best attempt at fixing these issues to make a runnable app. Since the download as is can’t run, and the “zip archive” does initialize and run, returning the error on two of the calls, seems it might be close. At this point I don’t know what else to do, so I’m looking for suggestions from you as to how to proceed.

Please advise.
Jim

Hello, @Jim_Austin.

I used version 7.1.8 to call these methods.
Try updating your backendless_sdk version to 7.1.8

Regards, Nikita.

Nikita,
You must have missed this line in my previous post:
“in the “zip archive” with backendless_sdk: ^7.1.8, Backendless.initAp
calls are optional, thus named.”
My code has been running on 7.1.8 from the beginning.

You’ve not yet addressed the issue in 3. above: the type mismatch between the type definition and the parameter call. And perhaps you can share how you modify the download; as I said in 3. and 4. above, the download I get is not runnable as downloaded.
Jim

Hello, @Jim_Austin.

Amazing problem.
I cannot reproduce your issue.

The third parameter of the invoke method is of type dynamic. It cannot return this error to you.
The only thing that comes to my mind in this case is that you have changed open source within your project.

Try to call following commands

flutter clean
flutter pub get

Best Regards, Nikita.

Nikita,
You are a marvel … that got it! The code for ’invoke’ shows that third parameter as dynamic, but Android Studio insisted it was type List. “Amazing problem” indeed, one I won’t soon forget.

I ran the ‘clean’ and ‘pub get’, changed the parameter variable types back to the original simple declarations, and A/S did not show that error. Ran the code, Missions accepted the four calls as valid, and unlocked the Springboard plan … a fine Christmas gift!

Thanks again for your help and for sticking with this ‘weird’ problem … have a good holiday season!
Jim

Happy to help)
Have a nice weekend :slightly_smiling_face:

Hello Jim and Nikita,

I had the very same problem as Jim. Independently, I made the very same modifications to the dowloaded source code. However, my pubspec.yaml file imported backendless_sdk: ^0.1.1.

I upgraded to backendless_sdk: ^7.1.8 and it fixed the parameters compile errors. However, Backendless.initApp() now requires named arguments. I modified the method call to use named arguments and everything worked!

I too, unlocked the Springboard plan and I have a question. I would like to use the CRM Blueprint as my Springboard application. My current application is blank. Can I create a project based on CRM and still continue working the missions? I would like to learn more using missions and gain insight using a built application.

Sorry, I have zero followers on twitter. I have social media accounts but I never use them.

Thanks,
Chuck

Hello @Chuck_H!

Could you please clarify if I understood you correctly:
You have already received Springboard for completing missions and you want to create a new application based on the blueprint?

Regards,
Alexander

Yes, I would also like to continue the missions from my current mission.

It’s my understanding that only one project is allowed with the Springboard

I think that I could learn Backendless faster by continuing the missions, at the same time, studying a completed application.

Thanks
Chuck

When you go through Missions and get to the Springboard milestone, you will get the Springboard plan only for one of your apps. However, you can have multiple apps on the Springboard plan. The plan can be obtained (for each individual app) through the Marketplace:

Regards,
Mark