Open Closed

How can we specify a service API version when creating ajax within database extension methods ? #5808


User avatar
0
raif created

Check the docs before asking a question: https://docs.abp.io/en/abp/latest/API/API-Versioning https://docs.abp.io/en/abp/7.3/UI/AspNetCore/Data-Tables

Check the samples to see the basic tasks: https://github.com/abpframework/abp-samples/tree/master/Api-Versioning [This example doesn't show how to integrate api versiong with Datatables ]

  • ABP Framework version: v7.3.1
  • UI Type: MVC /
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): ye
  • Exception message and full stack trace:
  • Request did not specify a service API version, but multiple candidate actions were found. Candidate actions: Siemens.PSSX.Odms.Models.v130.ModelController.GetListAsync (Siemens.PSSX.Odms.HttpApi) Siemens.PSSX.Odms.Models.v131.ModelController.GetListAsync (Siemens.PSSX.Odms.HttpApi)

We have more than one version of one of our APIs. We can easily see the versions through the Swagger interface and working as intended.

JS proxy configuration from .Web project as shown below;


  (function(){

    abp.utils.createNamespace(window, 'siemens.pSSX.odms.models.v130.model');
    
    ... ///
    
    siemens.pSSX.odms.models.v130.model.getList = function(input, ajaxParams) {
      var api_version = api_version ? api_version : '13.0';
      return abp.ajax($.extend(true, {
        url: abp.appPath + 'api/odms/models' + abp.utils.buildQueryString([{ name: 'filterText', value: input.filterText }, { name: 'name', value: input.name }, { name: 'description', value: input.description }, { name: 'serverName', value: input.serverName }, { name: 'cIMVersion', value: input.cIMVersion }, { name: 'creatorId', value: input.creatorId }, { name: 'creationTimeMin', value: input.creationTimeMin }, { name: 'creationTimeMax', value: input.creationTimeMax }, { name: 'lastModifierId', value: input.lastModifierId }, { name: 'lastModificationTimeMin', value: input.lastModificationTimeMin }, { name: 'lastModificationTimeMax', value: input.lastModificationTimeMax }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }, { name: 'api-version', value: input.api_version }]) + '',
        type: 'GET'
      }, ajaxParams));
    };  
 })();
 
  (function(){

    abp.utils.createNamespace(window, 'siemens.pSSX.odms.models.v131.model');

    siemens.pSSX.odms.models.v131.model.getList = function(input, ajaxParams) {
      var api_version = api_version ? api_version : '13.1';
      return abp.ajax($.extend(true, {
        url: abp.appPath + 'api/odms/models' + abp.utils.buildQueryString([{ name: 'filterText', value: input.filterText }, { name: 'name', value: input.name }, { name: 'description', value: input.description }, { name: 'serverName', value: input.serverName }, { name: 'cIMVersion', value: input.cIMVersion }, { name: 'creatorId', value: input.creatorId }, { name: 'creationTimeMin', value: input.creationTimeMin }, { name: 'creationTimeMax', value: input.creationTimeMax }, { name: 'lastModifierId', value: input.lastModifierId }, { name: 'lastModificationTimeMin', value: input.lastModificationTimeMin }, { name: 'lastModificationTimeMax', value: input.lastModificationTimeMax }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }, { name: 'api-version', value: input.api_version }]) + '',
        type: 'GET'
      }, ajaxParams));
    };
 })();

For the sake of simplicity, two different MVC UI were designed for two different API versions.


var l = abp.localization.getResource("Odms");

var modelService = siemens.pSSX.odms.models.v130.model;

var getFilter = function () {
    return {
        filterText: $("#FilterText").val(),
        name: $("#NameFilter").val(),
        description: $("#DescriptionFilter").val(),
        serverName: $("#ServerNameFilter").val(),
        cIMVersion: $("#CIMVersionFilter").val(),
        creatorId: $("#ServerNameFilter").val(),
        creationTimeMin: $("#CreationTimeFilterMin").val(),
        creationTimeMax: $("#CreationTimeFilterMax").val(),
        lastModifierId: $("#ServerNameFilter").val(),
        lastModificationTimeMin: $("#LastModificationTimeFilterMin").val(),
        lastModificationTimeMax: $("#LastModificationTimeFilterMax").val(),
    };
};
    
 var dataTable = $("#ModelsTable").DataTable(abp.libs.datatables.normalizeConfiguration({
     processing: true,
     serverSide: true,
     paging: true,
     searching: false,
     scrollX: true,
     autoWidth: false,
     scrollCollapse: true,
     order: [[1, "asc"]],
     ajax: **abp.libs.datatables.createAjax(modelService.getList, getFilter),**
     columnDefs: [
         {
             ... ///
         }
      ]
    }));

abp.libs.datatables.createAjax(modelService.getList, getFilter),

How can we specify a service API version when creating ajax ?

Log: 2023-09-18 20:21:27.944 +02:00 [INF] Request did not specify a service API version, but multiple candidate actions were found. Candidate actions: Siemens.PSSX.Odms.Models.v130.ModelController.GetListAsync (Siemens.PSSX.Odms.HttpApi) Siemens.PSSX.Odms.Models.v131.ModelController.GetListAsync (Siemens.PSSX.Odms.HttpApi)


11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    siemens.pSSX.odms.models.v130.model;

    This sample also uses the ajax to get the different results

    https://github.com/abpframework/abp-samples/blob/master/Api-Versioning/host/BookStore.WebApp/Pages/Index.cshtml#L9-L35

    https://github.com/abpframework/abp-samples/pull/126

  • User Avatar
    0
    raif created

    hi

    siemens.pSSX.odms.models.v130.model;

    This sample also uses the ajax to get the different results

    https://github.com/abpframework/abp-samples/blob/master/Api-Versioning/host/BookStore.WebApp/Pages/Index.cshtml#L9-L35

    https://github.com/abpframework/abp-samples/pull/126

    As far as I see, my question is not understood clearly,

    The examples above are not related to https://docs.abp.io/en/abp/latest/UI/AspNetCore/Data-Tables#ajax-adapter or I cannot make connection

    ajax: abp.libs.datatables.createAjax(acme.bookStore.books.book.getList, inputAction, responseCallback)

    If there is more than one version of acme.bookStore.books.book.getList, I encounter the following error.

    Request did not specify a service API version, but multiple candidate actions were found.

    acme.bookStore.books.book.getList('2.0') or similar approach doesn't help here

    So what should we do here ?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Request did not specify a service API version, but multiple candidate actions were found.

    Can you share a simple project to reproduce?

    liming.ma@volosoft.com

  • User Avatar
    0
    raif created

    hi

    Request did not specify a service API version, but multiple candidate actions were found.

    Can you share a simple project to reproduce?

    liming.ma@volosoft.com

    Sent

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will check your project asap.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    error NU1101: Unable to find package Siemens.PSSX.Users.EntityFrameworkCore. N o packages exist with this id in source(s): ABP Commercial NuGet Source,

    How can I restore this package?

  • User Avatar
    0
    raif created

    hi

    error NU1101: Unable to find package Siemens.PSSX.Users.EntityFrameworkCore. N
    o packages exist with this id in source(s): ABP Commercial NuGet Source,

    How can I restore this package?

    Sorry my bad, I forgot this one.. I replaced this one with Volo's Users package and shared it again

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will fix this and share a solution soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Try this

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    https://github.com/abpframework/abp/pull/17682

  • User Avatar
    0
    raif created

    hi

    Try this

    Hi thx a lot.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35