Pass an array of strings to Mendix REST service via JQuery

0
Hi all, I've been trying to pass to my Mendix rest service a list of string values. I did some research and saw that [t]o be able to map a list of String-/Float-/Boolean values, you need to set a many to many association to the Primitive entity in your RestServices module, or a subclass of the Primitive entity. However, after I've done that, the values don't seem to register. I'm not getting any errors, but the values just aren't accessible in my microflow when I make the request to the REST service. Here's how I've setup my entities to match the REST request: Here's my jQuery code that makes the request to the REST service on localhost: $.ajax({     url: 'http://localhost:8080/rest/getproducts/',     method: 'GET',     data: {         q: 'Test',         productsGUIDs: ['58828270132528344','58828270132528345'],     }, }).then(function(data) {     console.log(data); }); I've already tried changing the content-type attribute of the .ajax jquery call to JSON, but to no avail. I've also tried using JSON.stringify on the object before passing it through the data attribute.   The microflow exposed as 'getproducts' simply serializes the input object to JSON and returns the resulting string. This is done just so I can see if the values are being registered on the Mendix end. But I keep getting back the following string, which tells me that the values aren't being interpreted for some reason: {     "q": "Test",     "productsGUIDs": [], } Here's a snapshot of the exposed microflow:   Can anybody help me understand what I might be doing wrong? I need this functionality for an important app update.   ------- UPDATE: I got it figured out!! My domain model was good, but I had to publish my REST service microflow as a POST service rather than GET. Additionally, I updated the ajax call to use POST method rather than GET (to match the REST service), and I converted the data object to a JSON String using JSON.stringify and added the contentType: 'application/json' flag to the request. Here's the updated jQuery: $.ajax({     url: 'http://localhost:8080/rest/getproducts/',     method: 'POST',     contentType: 'application/json',     data: JSON.stringify({         q: 'Test',         productsGUIDs: ['58828270132528344','58828270132528345'],     }), }).then(function(data) {     console.log(data); });  
asked
1 answers
1

Change the request into:

 

$.ajax({
    url: 'http://localhost:8080/rest/getproducts/',
    method: 'GET',
    data: {
        q: 'Test',
        productsGUIDs: [
                {'pid': '58828270132528344'},
                {'pid': '58828270132528345'}
        ],
    },
}).then(function(data) {
    console.log(data);
});

 

and create a 'pid' attribute CAPCId. Process the objects after importing.

answered