The request parameter is invalid... Five days later

0 votes

Hello,

I'm very disapointed after five days to try to find a solution to my query problem, I try to update value based on this query :

for (int i = 0; i < mediaCount; i++)
            {
                string currentVideo = Regex.Match(jsonMedias["media"][i]["video"].ToString(), @".*\/([^/]*)$").Groups[1].Value.ToString().Replace(" ", "");
                string videoSelected = Regex.Match(RavrDataManager.Instance.CurrentVideo, @".*\/([^/]*)$").Groups[1].Value.ToString().Replace(" ", "");
                // If video url is same of selected video url
                if (currentVideo == videoSelected)
                {
                    // Addition old value to new value (+1)
                    int currentLike;
                    int.TryParse(jsonMedias["media"][i]["liked"].ToString(), out currentLike);
                    value = currentLike + 1;

                    Query q1 = QueryBuilder.Build("media.video", RavrDataManager.Instance.CurrentVideo, Operator.EQUALS); // Build query q1 for key1 equal to video and value1 equal to current video url  
                    Query q2 = QueryBuilder.Build("media.liked", value.ToString(), Operator.NOT_EQUALS); // Build query q2 for key2 equal to liked and value2 less than new value   
                    Query query = QueryBuilder.CompoundOperator(q1, Operator.AND, q2);

                    // Call storage to update value for key "liked"
                    storageService.UpdateDocumentByQuery(RavrConstant.dbName, RavrDataManager.Instance.CurrentCountryName, query, jsonString, callBackUpdate);
                    return;
                }
            }

is very basic query, I need to update key:"liked" for the current url video seleted

error and debug result are :


apiKeyf51f2393d29c9bc2ad211239076d32a42e58d7c3b9c6782bb560d4f5d9435fa5body{"app42":{"storage":{"jsonQuery":[{"key":"media.video","operator":"$eq","value":"http://s3.amazonaws.com/ravrmedia/Spain/Rafting Spain.mp4"},{"compoundOpt":"$and"},{"key":"media.liked","operator":"$ne","value":"6"}],"jsonDoc":"{"media":[ {"id":"1", "isWtfVideo":"false", "title":"Child Climbs Historic Human Tower", "price":"0", "description":"We are watching, along with thousands of spectators, the success of a challenging old tradition in Vilafranca which is the building of a human tower.", "cityName":"Vilafranca", "isHotelVideo":"false", "liked":"5", "image":"http://s3.amazonaws.com/ravrmedia/Spain/img/Child Climbs Historic Human Tower.jpg", "thumb":"http://s3.amazonaws.com/ravrmedia/Spain/img/Child Climbs Historic Human Tower.jpg", "video":"http://s3.amazonaws.com/ravrmedia/Spain/Child Climbs Historic Human Tower.mp4"}, {"id":"2", "isWtfVideo":"false", "title":"City Guide of Barcelona", "price":"0", "description":"We are being taken on a little guided tour of Barcelona. We discover the Seaside, the Sagrada Família \"a Roman Catholic Church\" Mercado de La Boqueria \"the main market\", Plaça Reial, Passeig de Gràcia (one of the main avenues), La Rambla \"a popular street\", Montjuïc Castle, Torre de Collserola \"a uniquely designed tower\" and Catalonia Square.", "cityName":"Barcelona", "isHotelVideo":"false", "liked":"5", "image":"http://s3.amazonaws.com/ravrmedia/Spain/img/City Guide of Barcelona.jpg", "thumb":"http://s3.amazonaws.com/ravrmedia/Spain/img/City Guide of Barcelona.jpg", "video":"http://s3.amazonaws.com/ravrmedia/Spain/City Guide of Barcelona.mp4"}, {"id":"3", "isWtfVideo":"false", "title":"Hot Air Balloon Flight Spain", "price":"0", "description":"We are being taken on a hot air ballon trip over La Cerdanya.", "cityName":"La Cerdanya", "isHotelVideo":"false", "liked":"5", "image":"http://s3.amazonaws.com/ravrmedia/Spain/img/Hot Air Balloon Flight Spain.jpg", "thumb":"http://s3.amazonaws.com/ravrmedia/Spain/img/Hot Air Balloon Flight Spain.jpg", "video":"http://s3.amazonaws.com/ravrmedia/Spain/Hot Air Balloon Flight Spain.mp4"}, {"id":"4", "isWtfVideo":"false", "title":"Michelin Chef Susi Diaz at La Finca restaurant", "price":"0", "description":"We are watching Susia Diaz, a Michelin Star chef, and her team cooking in her restaurant called La Fincha in Elche.", "cityName":"Elche", "isHotelVideo":"false", "liked":"5", "image":"http://s3.amazonaws.com/ravrmedia/Spain/img/Michelin Chef Susi Diaz at La Finca restaurant.jpg", "thumb":"http://s3.amazonaws.com/ravrmedia/Spain/img/Michelin Chef Susi Diaz at La Finca restaurant.jpg", "video":"http://s3.amazonaws.com/ravrmedia/Spain/Michelin Chef Susi Diaz at La Finca restaurant.mp4"}, {"id":"5", "isWtfVideo":"false", "title":"Rafting Spain", "price":"0", "description":"We are rafting in the Gállego River in Huesca.", "cityName":"Huesca", "isHotelVideo":"false", "liked":"5", "image":"http://s3.amazonaws.com/ravrmedia/Spain/img/Rafting Spain.jpg", "thumb":"http://s3.amazonaws.com/ravrmedia/Spain/img/Rafting Spain.jpg", "video":"http://s3.amazonaws.com/ravrmedia/Spain/Rafting Spain.mp4"}, {"id":"6", "isWtfVideo":"false", "title":"Timelapse City of Arts and Sciences", "price":"0", "description":"We are standing in an outdoors section of L'Oceanogràfic, an oceanarium in Valencia, in time-lapse.", "cityName":"Valencia", "isHotelVideo":"false", "liked":"5", "image":"http://s3.amazonaws.com/ravrmedia/Spain/img/Timelapse City of Arts and Sciences.jpg", "thumb":"http://s3.amazonaws.com/ravrmedia/Spain/img/Timelapse City of Arts and Sciences.jpg", "video":"http://s3.amazonaws.com/ravrmedia/Spain/Timelapse City of Arts and Sciences.mp4"} ]}"}}}collectionNameSpaindbNameRAVRMEDIASsessionId464baa26-7cc2-4534-bbc3-562f073dc2d4timeStamp2016-07-23T11:27:00.940Zversion1.0
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.util.Util:SortAndConvertTableToString(Dictionary`2)
com.shephertz.app42.paas.sdk.csharp.util.Util:Sign(String, Dictionary`2)
com.shephertz.app42.paas.sdk.csharp.storage.StorageService:UpdateDocumentByQuery(String, String, Query, String, App42CallBack)
RavrLikeManager:ProcessMedias(String) (at Assets/_RAVR_V1/Scripts/RavrLikeManager.cs:137)
RavrLikeManager:Update() (at Assets/_RAVR_V1/Scripts/RavrLikeManager.cs:62)

PUT URI : https://api.shephertz.com/cloud/1.0/storage/updateDocsByQuery/dbName/RAVRMEDIAS/collectionName/Spain?
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePut(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.storage.StorageService:UpdateDocumentByQuery(String, String, Query, String, App42CallBack)
RavrLikeManager:ProcessMedias(String) (at Assets/_RAVR_V1/Scripts/RavrLikeManager.cs:137)
RavrLikeManager:Update() (at Assets/_RAVR_V1/Scripts/RavrLikeManager.cs:62)


errorValue : {"app42Fault":{"httpErrorCode":400,"appErrorCode":1400,"message":"Bad Request","details":"The Request parameters are invalid"}}
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

I dont understand where problem com from... 

 

Thanks for help

asked Jul 23, 2016 in Unity by ibompuis (20 points)

1 Answer

0 votes

Hi,

Apologies for getting late back to you. We have added new method in sample file and integrate the same use case of query, please download using the below link:

http://cdn.shephertz.com/repository/files/6ab7a4745c0c2dba0bd40d6d5a60a354c8ab5b72dbc520dafa0536a91b861dc8/5384781a6efab0d807ed3e93c97899031faa98e4/SampleProject1.zip

If you still face any issue then let us know. 

We are happy to help you. 

Regards,

Himanshu Sharma

answered Jul 25, 2016 by hs00105 (2,005 points)
Hi,

Thanks for take time again :-) but, your example don't work
I have exactly the same error...

You can find your class, (modified to work with jsonArray), please test it and  you can see this doesn't work.

Anyone know how to use query ? I don't understand why is so dificult for a simple JSON :-(

using UnityEngine;
using System.Collections;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.storage;
using AssemblyCSharp;
using System.Net;
using SimpleJSON;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public class TestScript : MonoBehaviour {
    ServiceAPI sp = null;
    StorageService storageService = null; // Initialising Storage Service.
    public int max = 2;
    public int offSet = 1;
    public string dbName = "LIVEVIEW";
    public string collectionName = "Test";
    private int value;
    StoragesResponse callBack = new StoragesResponse();
    public string success, box;
    public string newJsonDoc = "";
#if UNITY_EDITOR
    public static bool Validator(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
    { return true; }
#endif
    void Start()
    {
#if UNITY_EDITOR
        ServicePointManager.ServerCertificateValidationCallback = Validator;
#endif
        sp = new ServiceAPI("6ab7a4745c0c2dba0bd40d6d5a60a354c8ab5b72dbc520dafa0536a91b861dc8", "51023784bae2286ca6b3d4d70029892cc089d0e6d297e95c57f50405ce7cab30");
    }

    // Update is called once per frame
    void Update()
    {

    }
    void OnGUI()
    {
        if (Time.time % 2 < 1)
        {
            success = callBack.GetResult().ToString();
            newJsonDoc = callBack.GetResult();
        }
        // For Setting Up ResponseBox.
        GUI.TextArea(new Rect(10, 5, 1000, 175), success);

        //===================================**************=========================================
        if (GUI.Button(new Rect(50, 200, 200, 30), "Fetch JSON Document"))
        {
            storageService = sp.BuildStorageService(); // Initializing Storage Service.
            storageService.FindDocumentById("LIVEVIEW", "Test", "5795b30ae4b021d736eb80e1", callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(260, 200, 200, 30), "Update Document"))
        {
            JObject jsoObject = JSON.Parse(newJsonDoc);
            
            JArray jsonArray = (JArray)jsoObject["media"];

            for (int i = 0; i < jsonArray.Count; i++)
            {
                Debug.Log("A");
                string currentVideo = Regex.Match(jsonArray[i]["video"].ToString().Replace("\"", ""), @".*\/([^/]*)$").Groups[1].Value.ToString().Replace(" ", "");
                
                Debug.Log(currentVideo);
                string videoSelected = Regex.Match("http://s3.amazonaws.com/ravrmedia/Spain/Child Climbs Historic Human Tower.mp4", @".*\/([^/]*)$").Groups[1].Value.ToString().Replace(" ", "");
                Debug.Log(videoSelected);
                // If video url is same of selected video url
                if (currentVideo == videoSelected)
                {
                    Debug.Log("B");
                    // Addition old value to new value (+1)
                    int currentLike;
                    int.TryParse(jsonArray[i]["liked"].ToString().Replace("\"", ""), out currentLike);
                    value = currentLike + 1;

                    Query q1 = QueryBuilder.Build("media.video", currentVideo, Operator.LIKE); // Build query q1 for key1 equal to video and value1 equal to current video url  
                    Query q2 = QueryBuilder.Build("media.liked", value.ToString(), Operator.LIKE); // Build query q2 for key2 equal to liked and value2 less than new value   
                    Query query = QueryBuilder.CompoundOperator(q1, Operator.AND, q2);
                    Debug.Log("Counter" + query.GetStr());
                    StorageService storageService = new StorageService("6ab7a4745c0c2dba0bd40d6d5a60a354c8ab5b72dbc520dafa0536a91b861dc8", "51023784bae2286ca6b3d4d70029892cc089d0e6d297e95c57f50405ce7cab30");
                    string ndoc = jsoObject.ToString();
                     App42Log.SetDebug(true);

                    storageService.UpdateDocumentByQuery("LIVEVIEW", "Test", query, JSON.Parse(newJsonDoc).ToString(), callBack);
                    return;
                }
            }
        }
    }
}
Hi  ibompuis,

It seems like you change the code from:

App42StorageService app42StorageService = new App42StorageService("APIKey", "SecretKey");
                   
to

StorageService storageService = new StorageService("APIKEY", "SECERTKEY");
 
I have added new class file name as App42StorageService.cs. Can you call the update method of that class and let me know if you still face any issue.

Please have a look into it and let me know if it helps.

Regards,
Himanshu Sharma
Ok added your class and get this error :

errorValue : {"app42Fault":{"httpErrorCode":404,"appErrorCode":2608,"message":"Not Found","details":"No document in the collection 'Test' exists for given query"}}
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
The error appear when I use NOT_EQUAL in query if I use LIKE query works but Liked value never updated in JSON...
you can test it with :

using UnityEngine;
using System.Collections;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.storage;
using AssemblyCSharp;
using System.Net;
using SimpleJSON;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public class TestScript : MonoBehaviour {
    ServiceAPI sp = null;
    StorageService storageService = null; // Initialising Storage Service.
    public int max = 2;
    public int offSet = 1;
    public string dbName = "LIVEVIEW";
    public string collectionName = "Test";
    private int value;
    StoragesResponse callBack = new StoragesResponse();
    public string success, box;
    public string newJsonDoc = "";
#if UNITY_EDITOR
    public static bool Validator(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
    { return true; }
#endif
    void Start()
    {
#if UNITY_EDITOR
        ServicePointManager.ServerCertificateValidationCallback = Validator;
#endif
        sp = new ServiceAPI("6ab7a4745c0c2dba0bd40d6d5a60a354c8ab5b72dbc520dafa0536a91b861dc8", "51023784bae2286ca6b3d4d70029892cc089d0e6d297e95c57f50405ce7cab30");
    }

    // Update is called once per frame
    void Update()
    {

    }
    void OnGUI()
    {
        if (Time.time % 2 < 1)
        {
            success = callBack.GetResult().ToString();
            newJsonDoc = callBack.GetResult();
        }
        // For Setting Up ResponseBox.
        GUI.TextArea(new Rect(10, 5, 1000, 175), success);

        //===================================**************=========================================
        if (GUI.Button(new Rect(50, 200, 200, 30), "Fetch JSON Document"))
        {
            storageService = sp.BuildStorageService(); // Initializing Storage Service.
            storageService.FindDocumentById("LIVEVIEW", "Test", "5795b30ae4b021d736eb80e1", callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(260, 200, 200, 30), "Update Document"))
        {
            JObject jsoObject = JSON.Parse(newJsonDoc);
            
            JArray jsonArray = (JArray)jsoObject["media"];

            for (int i = 0; i < jsonArray.Count; i++)
            {
                Debug.Log("A");
                string currentVideo = Regex.Match(jsonArray[i]["video"].ToString().Replace("\"", ""), @".*\/([^/]*)$").Groups[1].Value.ToString().Replace(" ", "");
                
                Debug.Log(currentVideo);
                string videoSelected = Regex.Match("http://s3.amazonaws.com/ravrmedia/Spain/Child Climbs Historic Human Tower.mp4", @".*\/([^/]*)$").Groups[1].Value.ToString().Replace(" ", "");
                Debug.Log(videoSelected);
                // If video url is same of selected video url
                if (currentVideo == videoSelected)
                {
                    Debug.Log("B");
                    // Addition old value to new value (+1)
                    int currentLike;
                    int.TryParse(jsonArray[i]["liked"].ToString().Replace("\"", ""), out currentLike);
                    value = currentLike + 1;

                    Debug.Log(value.ToString());

                    Query q1 = QueryBuilder.Build("media.video", "http://s3.amazonaws.com/ravrmedia/Spain/Child Climbs Historic Human Tower.mp4", Operator.LIKE); // Build query q1 for key1 equal to video and value1 equal to current video url  
                    Query q2 = QueryBuilder.Build("media.liked", value.ToString(), Operator.LIKE); // Build query q2 for key2 equal to liked and value2 less than new value   
                    Query query = QueryBuilder.CompoundOperator(q1, Operator.AND, q2);
                    Debug.Log("Counter" + query.GetStr().ToString());
                    App42StorageService app42StorageService = new App42StorageService("6ab7a4745c0c2dba0bd40d6d5a60a354c8ab5b72dbc520dafa0536a91b861dc8", "51023784bae2286ca6b3d4d70029892cc089d0e6d297e95c57f50405ce7cab30");
                    string ndoc = jsoObject.ToString();
                     App42Log.SetDebug(true);

                    app42StorageService.UpdateDocumentByQuery("LIVEVIEW", "Test", query, JSON.Parse(newJsonDoc).ToString(), callBack);
                    return;
                }
            }
        }
    }
}
Hi Ibompuis,

I believe the query has been resolved for you. If you still facing any issue then please let us know.

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...