Hi @pgr @RMN ! finally I could request to api graphql of suite8 from a custom javascript. I’m rendering the edit/detail page with legacy view.
- I need it to get XSRF-TOKEN to send it as a header to the ajax request.
- Create a request variable to get a list of records (query)
- Create a variables var to set the criteria and other stuff.
var token = getCookie('XSRF-TOKEN');
console.log('token');
console.log(token);
var operationName = 'getRecordList';
var query = `
query getRecordList($module: String!, $limit: Int, $offset: Int, $criteria: Iterable, $sort: Iterable) {
getRecordList(module:$module, limit:$limit, offset: $offset, criteria: $criteria, sort: $sort) {
id
_id
meta
records
__typename
}
}
`;
var variables = {
'criteria': {
'name': "",
'orderBy': "",
'searchModule': "gcoop_estados",
'sortOrder': "",
'filters': {
'terminal': {
'field': "terminal",
'fieldType': "bool",
'operator': "=",
'values': [1]
}
}
},
'module': 'gcoop_estados',
'limit': 20,
'offset': 0,
'sort': {
'orderBy': "",
'sortOrder': "DESC"
}
};
var r = $.ajax({
async: true,
url: '/api/graphql',
method: 'POST',
ContentType: 'application/json',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'X-XSRF-TOKEN': token
},
data: JSON.stringify({
oerationName: operationName, //'getRecordList',
query: query,
variables: variables
})
}).done(function() {
console.log(r.responseText)
var response = $.parseJSON(r.responseText);
let records = response.data.getRecordList.records;
let dropdown = $('#status');
dropdown.empty();
dropdown.prop('selectedIndex', 0);
$.each(records, function(key, entry) {
console.log(key);
console.log(entry);
console.log(entry.attributes.id); // key
console.log(entry.attributes.name); // label
})
});
The response looks something like this:
{
"data": {
"getRecordList": {
"id": "/api/record-list/gcoop_estados",
"_id": "gcoop_estados",
"meta": {
"offsets": {
"current": 0,
"next": -1,
"prev": -1,
"end": 0,
"total": 1,
"totalCounted": false
},
"ordering": {
"orderBy": "",
"sortOrder": "ASC"
}
},
"records": [
{
"id": "41f2fd13-2959-9d80-99c4-63492b14e2fe",
"module": "gcoop-estados",
"type": "gcoop_estado",
"attributes": {
"module_name": "gcoop_estados",
"object_name": "gcoop_estado",
"id": "41f2fd13-2959-9d80-99c4-63492b14e2fe",
"name": "Finalizado",
"date_entered": "2022-10-14 09:27:39",
"date_modified": "2022-10-14 09:27:39",
"modified_user_id": "1",
"modified_by_name": {
"user_name": "admin",
"id": "1"
},
"created_by": "1",
"created_by_name": {
"user_name": "admin",
"id": "1"
},
"description": "",
"deleted": "",
"codigo": "004",
"terminal": "true",
"gcoop_sector_id": "",
"gcoop_sector_name": {
"name": "",
"id": ""
}
},
"acls": [
"list",
"edit",
"view",
"delete",
"export",
"import"
]
}
],
"__typename": "RecordList"
}
}
}
Hope it helps!