Got Message 'json parameter is not provided.' When Creating Table

8 posts / 0 new
Last post
riverbedsupport
Got Message 'json parameter is not provided.' When Creating Table

Hello,

I am trying to create a table but always got a response like

"messages":["json parameter is not provided."],

"statusCode":400

 

What am I missing here?  Please help!

#####################################################################

var mqKey = '...XoQf';

$.ajax({

        type: 'POST',
        url: 'https://www.mapquestapi.com/datamanager/v2/create-table?key='+mqKey+'&inFormat=json',
        dataType: 'JSON',
        data:{
            "tableName":"mqap.ASSETS_LOCATIONS",
            //"friendlyName": "friendly_name",
            "notes": "notes",
            "columns": [
                {
                    "name": 'UserAccountSelected',
                    "type": "VARCHAR"
                },
                {
                    "name": 'FullAddress',
                    "type": "VARCHAR"
                },
                {
                    "name": 'Geography',
                    "type": "VARCHAR"
                },
                {
                    "name": 'TotalAssets',
                    "type": "INT"
                }
            ],
            "isPublic": false
        },
        success: function(data, status, xml){
            console.log('iam in success');
            console.log(data);
            console.log(status);
            console.log(xml);
        },
        error: function(xml, status, error){
            console.log('iam in error');
        },
        complete: function(xml, status){
            console.log('iam in complete')
            console.log(xml);
            console.log(status)
        }
    });

#####################################################################################

Response:

{
  "readyState": 4,
  "responseText": "{\"info\":{\"copyright\":{\"imageAltText\":\"© 2017 MapQuest, Inc.\",\"imageUrl\":\"http://api.mqcdn.com/res/mqlogo.gif\",\"text\":\"© 2017 MapQuest, Inc.\"},\"messages\":[\"json parameter is not provided.\"],\"statusCode\":400}}",
  "status": 200,
  "statusText": "success"
}

 

Thanks.


MQBrianCoakley
Try converting the json to a
Try converting the json to a string before sending it over: JSON.stringify({...})   The sample data manager app can help provide some javascript help.

riverbedsupport
Thanks MQBrianCoakley for

Thanks MQBrianCoakley for your helpful tip.  

Another question is how do I select by column?  Let's say I have a column named 'UserAccountSelected' and I want to select all records where UserAccountSelected='aaa'.

I see in Body Parameters, it has 'extraCriteria' and 'parameters' but don't know how to use it.  Please give me an example.

Thank you very much.


MQBrianCoakley
You can see the full format
You can see the full format for the hostedData parameter here. But basically it would be like this.   hostedDataList:[{tableName:"mqap.tableName", extraCriteria:"UserAccountSelected=?", parameters:["aaa"], columnNames:[]}]  

riverbedsupport
Hi MQBrianCoakley,

Hi MQBrianCoakley,

I still got the messages: 'json parameter is not provided'.

Please help see my code below:

var myData = JSON.stringify({
        "hostedDataList":[
        {
            "tableName":"mqap.<%= mqKey %>_Assets_Locations", 
            "extraCriteria":"UserAccountSelected=?", 
            "parameters":["aaabbbccc"], 
            "columnNames":["mqap_geography","UserAccountSelected","Location","TotalAssets"]
        }]
    });
    $.ajax({
        type: 'POST',
        //cache: false,
        url: 'https://www.mapquestapi.com/datamanager/v2/get-table-data?key=<%= mqKey %>&inFormat=json',
        //dataType: 'JSON',
        data: myData,
        success: function(data){
            console.log('iam in success');
            console.log(myData);
            console.log(data);
        },
        error: function(xhr, status, error){
            // do something if there was an error
            console.log('iam in error');
        }
    });

 

Response:

{
  "info": {
    "copyright": {
      "imageAltText": "© 2017 MapQuest, Inc.",
      "imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
      "text": "© 2017 MapQuest, Inc."
    },
    "messages": [
      "json parameter is not provided."
    ],
    "statusCode": 400
  }
}

 

Thank you


MQBrianCoakley
For a get-table-data request
For a get-table-data request you don't need the hostedDataList. You can only get one table's data so just use the hosted data parameters without the list.

riverbedsupport
Hi MQBrianCoakley,

Hi MQBrianCoakley,

Thanks for being patient with me.  I've tried those parameters below but still got "json parameter is not provided.".

data: "?hostedData=mqap.<%= mqKey %>_assets_locations|user_account_selected=?|aaabbbccc|mqap_geography,user_account_selected,location,total_assets"

 

data: JSON.stringify({ "hostedData":{"tableName":"mqap.<%= mqKey %>_assets_locations", "extraCriteria":"user_account_selected=?", "parameters":["aaabbbccc"], "columnNames":["mqap_geography","user_account_selected","location","total_assets"]}})


MQBrianCoakley
Here's how I did it.
Here's how I did it.   <!DOCTYPE html> <html>     <head>         <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>         <script>             var duh;             function doit() {                 var myData = JSON.stringify({                     "tableName":"mqap.KEY_assets_locations",                     "parameters":["Sunnyvale, CA, US"],                     "extraCriteria":"location=?", //                    "parameters":["aaabbbccc"], //                    "extraCriteria":"user_account_selected=?",                     "columnNames":["mqap_geography","user_account_selected","location","total_assets"]                 });                 $.ajax({                     type: 'POST',                     url: 'https://www.mapquestapi.com/datamanager/v2/get-table-data?key=KEY&inForm...',                     data: "json=" + myData,                     success: function(data){                         console.log(data);                         duh = data;                         if (data.data && data.data.rows && data.data.rows.length > 0) {                             $("#divout").html(data.data.rows[0][0]);                         } else {                             $("#divout").html(data.info.messages[0]);                         }                     }                 });             }         </script>     </head>     <body>         <input type = "button" value = "GO" onclick = "doit();"/>         <div id = "divout"></div>     </body> </html>   I had to comment out a couple lines to get it to work. Unfortunately the column name user_account_selected is invalid. To avoid abuse of the api, extraCriteria values are not allowed to have "select" in them. This keeps people from doing things they shouldn't be. I'll submit an enhancement request to document this.