Quickblox flutter custom objects update not working

102 Views Asked by At

According to Quickblox documentation here updating a custom object from the flutter SDK can be done using this sample:

String className = "TestFlutterClass";

String id = "5d4175afa0eb4715cae5b63f";
    
Map<String, Object> fieldsMap = Map();
fieldsMap['testString'] = "testField1";
fieldsMap['testInteger'] = 123;
fieldsMap['testBoolean'] = true;

try {
  QBCustomObject? customObject = await QB.data.update(className, id: id, fields: fieldsMap);
} on PlatformException catch (e) {
  // Some error occurred, look at the exception message for more details
}

This code above doesn't seem to work or return anything.

I have also tried to update the custom object by posting HTTP to the Rest API using the code below

String url = "https://api.quickblox.com/data/GAMES/61794c291558ea0059ce2c90.json";
         
Map map = {'data': { 'PLAYERS_STATUS': sts},};

await apiRequest(url, map);

Future<String>  apiRequest(String url, Map jsonMap) async {
    HttpClient httpClient = new HttpClient();
    HttpClientRequest request = await httpClient.postUrl(Uri.parse(url));
    request.headers.set('content-type', 'application/json');
    request.headers.set('QB-token', session);
    request.add(utf8.encode(json.encode(jsonMap)));
    HttpClientResponse response = await request.close();
    // todo - you should check the response.statusCode
    String reply = await response.transform(utf8.decoder).join();
    httpClient.close();
    return reply;
}

This code returns an error with message

Resource not found

Now I know that the record exists because I can see the record on my dashboard and all class permissions are open.

Any help is welcome!

1

There are 1 best solutions below

1
gemcollector On

In Server API for updating record you need to use PUT request method. I can see you sent POST request. Try using PUT request method instead of POST https://api.flutter.dev/flutter/dart-io/HttpClient/putUrl.html