Passing multiple variables to Api_Action

having a hard time passing 2 params to api_action… 1 gets passed ok, but the 2nd doesn’t worktried this
$.get(ew.getApiUrl(“getAuditFieldHistory”) + ‘/’ + sTableName + ‘?x_FieldName=’ + sFieldName + ‘&x_KeyValue=’ + sKeyValue)
sTableName goes through as arg
x_FieldName goes trhoug as param
x_KeyValue does not get through = nullthis fails as well
$.get(ew.getApiUrl(“getAuditFieldHistory”) + ‘/’ + sTableName + ‘?x_FieldName=’ + sFieldName + ‘?x_KeyValue=’ + sKeyValue)this explodes:
$.get(ew.getApiUrl(“getAuditFieldHistory”) + ‘/’ + sTableName + ‘/’ + sFieldName + ‘/’ + sKeyValue)api_action is:
$app->get(‘/getAuditFieldHistory/{x_TableName}’, function ($request, $response, $args) {

    $sTable = $args["x_TableName"] ?? null ;
    $sField = Param("x_FieldName") ?? null ;
    $sKeyValue = Param("x_KeyValue") ?? null ;

as well tried
$app->get(‘/getAuditFieldHistory/{x_TableName, x_FieldName, x_KeyValue}’, function ($request, $response, $args) {
which blew up in a hurry.couldn’t find anything useful in teh help about multiple parameters

i worked around it with, not sure if this is best practice…JS:
$.get(ew.getApiUrl(“getAuditFieldHistory”) + ‘/’ + sTableName + ‘&’ + sFieldName + ‘&’ + sKeyValue)
…in $app->get(‘/getAuditFieldHistory/{x_FieldInfo}’, function ($request, $response, $args) {
$fields = explode(“&”, $args[“x_FieldInfo”]);

split apart and check then get and return data

It depends on how you define your route for your API action, the preferred way is:

$app->get('/getAuditFieldHistory/{table}/{field}/{key}', function ($request, $response, array $args) {
    // Get the arguments by $args['table'], $args['field'] and $args['key']
});

Read How to create routes for details.

1 Like

i was looking at that but didn’t scroll down far enough.did:

$.get(ew.getApiUrl("getAuditFieldHistory") + '/' + sTableName + '/' + sFieldName + '/' + sKeyValue)



$app->get('/getAuditFieldHistory[/{params:.*}]', function ($request, $response, $args) {
$fields = explode('/', $args['params']);
...
}

similar concept to what I had before but cleaner…thanks,

1 Like