Interactive console returning results vs api call from python

If I generate a request using the interactive console tool, I get a response including fields not included when copying the code generated by the tool and running it in python.

For example, when I make an API call on the web console I get 48 fields and when I make the call in python I only get 40. (This is comparing the same item) Looking at the two calls only 23 of the fields are shared, the rest are completely different.

I have tried to change permissions when making the API call to “disableentitlement” but does not change the result

any help would be great!

Hello @Jamie ,

More info is required.
Please provide the full request info (the action.service pair and all the params) as well as the response returned from the interactive web console and that returned when running your Python code.

You should, of course, mask sensitive data such as your API secret.

Further, note that since the console code responsible for making the request is pure JS, you can use your browser’s dev tools to see the full request it issued (look at the network tab).
This can help you in spotting possible differences and also make it easier for you to post here (again, mask the KS, please).

Cheers,

Hi @Jess,

This is the request, just trying to get all the media from a specific category

config = KalturaConfiguration(partner_id)
config.serviceUrl = "https://www.kaltura.com/"
client = KalturaClient(config)
ks = client.session.start(
    token,
    email,
    KalturaSessionType.ADMIN,
    partner_id)

client.setKs(ks)

filter = KalturaMediaEntryFilter()
filter.categoriesIdsMatchOr = id
filter.orderBy = KalturaMediaEntryOrderBy.CREATED_AT_DESC
pager = KalturaFilterPager()
pager.pageSize = 500
result = client.media.list(filter, pager)

The first item from the web console response:

{
      "mediaType": 1,
      "conversionQuality": 7435211,
      "sourceType": "6",
      "dataUrl": "data url",
      "flavorParamsIds": "param id",
      "plays": 1,
      "views": 2,
      "lastPlayedAt": 1512655200,
      "width": 1280,
      "height": 720,
      "duration": 3453,
      "msDuration": 3453000,
      "id": "an id",
      "name": "GSN-LTT",
      "partnerId": an id,
      "userId": "user name",
      "creatorId": "email",
      "tags": "geothermal energy, indonesia",
      "categories": "",
      "categoriesIds": "",
      "status": 2,
      "moderationStatus": 6,
      "moderationCount": 0,
      "type": 1,
      "createdAt": 1495133675,
      "updatedAt": 1556016025,
      "rank": 0,
      "totalRank": 0,
      "votes": 0,
      "downloadUrl": "a download url",
      "licenseType": -1,
      "version": 0,
      "thumbnailUrl": "a thumbnail url",
      "accessControlId": an id,
      "replacementStatus": 0,
      "partnerSortValue": 0,
      "conversionProfileId": another id,
      "rootEntryId": "entry id",
      "operationAttributes": [],
      "entitledUsersEdit": "",
      "entitledUsersPublish": "",
      "entitledUsersView": "",
      "capabilities": "",
      "displayInSearch": 1,
      "blockAutoTranscript": false,
      "objectType": "KalturaMediaEntry"
    }

The first item from the python response:

{
    "accessControlId": "an id",
    "adminTags": "",
    "applicationVersion": "",
    "application__null": "",
    "blockAutoTranscript": "False",
    "categories": "",
    "categoriesIds": "",
    "conversionProfileId": "profile id",
    "conversionQuality": "7435211",
    "creatorId": "an id",
    "creditUrl": "",
    "creditUserName": "",
    "description": "a description",
    "displayInSearch": "1",
    "endDate__null": "",
    "entitledUsersEdit": "",
    "entitledUsersPublish": "",
    "entitledUsersView": "",
    "groupId__null": "",
    "licenseType": "-1",
    "mediaType": "1",
    "msDuration": "3453000",
    "name": "GSN-LTT",
    "objectType": "KalturaMediaEntry",
    "operationAttributes": { "-": ""},
    "parentEntryId": "",
    "partnerData": "",
    "partnerSortValue": "0",
    "redirectEntryId": "",
    "referenceId": "",
    "searchProviderId": "",
    "searchProviderType__null": "",
    "sourceType": "6",
    "sourceVersion": "",
    "startDate__null": "",
    "streams": { "-": ""},
    "tags": "geothermal energy, indonesia",
    "templateEntryId": "",
    "type": "1",
    "userId": "user id"
}

I hope this explains the problem more clearly.

I will have a look at the network tab as you suggested in the meantime.

Hi @Jamie ,

I am unable to reproduce.

If anything, the response I get in the web console UI has fewer KalturaMediaEntry members, not more. The default response format in the web console is JSON, when setting it to XML (which is also what all the API clients use), the additional fields are returned.

This clearly shouldn’t be the case; the response should be the same, irrespective of the requested format. We’ll look into that but, since:
a. The web console is only meant for initial testing/experimentation
b. You are actually reporting the opposite result (which is far more important to resolve, in light of what I wrote in the clause above)

I suggest we focus on understanding the issue you’re actually seeing.

Firstly, let’s ensure the KS string used has the same attributes in both cases. If you need my help with that, send me a private message with these two strings so I can decode and compare (do not post the KS strings here of course).

Note that disableentitlement is indeed important when the entries in question are members of a category for which content entitlement is enabled but not setting this privilege will never result in the outcome you’ve described. Entries will either be returned or they won’t be but they will not be returned with fewer object members due to content entitlement enforcement.

Secondly, let’s set the pageSize to 1 in the console (simply so that we can deal with a single object in the response, not for any other reason).

Next, please run the below Python code using the official API client from PyPI - KalturaApiClient · PyPI (I’ve no reason to assume you’re using anything else but I want to make sure):

from KalturaClient import *
from KalturaClient.Plugins.Core import *
from pprint import pprint

partner_id = 
partner_admin_secret = ""
user_id=""
config = KalturaConfiguration(partner_id)
config.serviceUrl = "https://www.kaltura.com/"
client = KalturaClient(config)
ks = client.session.start(
      partner_admin_secret,
      user_id,
      KalturaSessionType.ADMIN,
      partner_id)
client.setKs(ks)

filter = KalturaMediaEntryFilter()
filter.orderBy = KalturaMediaEntryOrderBy.CREATED_AT_DESC
pager = KalturaFilterPager()
pager.pageSize = 1 

result = client.media.list(filter, pager)
for obj in result.objects:
        pprint(vars(obj))

Note my use of pprint which makes the result easy to read.

Cheers,

Hi @Jess,

After copying the code you sent me to run I have found the problem.

First, it is nothing to do with the ks. I have 3 methods for generating a ks (due to me trying to figure out why I was not getting the results) all of which did not give the same result as the web console. This is weird as one of the authentication methods is literally copied and pasted. They all also work with the fixed version of the code though.

However, I digress, after copying and pasting your code it magically worked. At first, I was quite confused, it turns out my method of printing the results was causing the problem. -.-

By simply replacing this…

for obj in result.getObjects():
    json_acceptable_string = obj.toParams().toJson()
    json_obj = json.loads(json_acceptable_string)
    print(json.dumps(json_obj, sort_keys=True, indent=4))

… with this, it fixed the problem

for obj in result.objects:
        pprint(vars(obj))

I can’t thank you enough!

May I make a request to add a toString/pretty print method to KalturaResponse

As for sanity reasons I tried to do the same thing in java and got the same result. This is probably because I tried to print the result like this…

for(MediaEntry obj : result.results.getObjects()){
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonParser jp = new JsonParser();
    JsonElement je = jp.parse(obj.toParams().toString());
    String prettyJsonString = gson.toJson(je);
    System.out.println(prettyJsonString);
}

This really threw me when my result were…

body:
{"filter":{"objectType":"KalturaMediaEntryFilter","orderBy":"-createdAt","categoriesIdsMatchOr":"65623171"},"pager":{"objectType":"KalturaFilterPager"},"ignoreNull":true,"format":1,"clientTag":"java:22-01-10","apiVersion":"17.18.0","ks":""}


21:01:03.182: debug - response [935a71ba-a0a7-4b7a-b53b-d3120b3ac5c3::media.list] body:
{"objects":[{"mediaType":1,"conversionQuality":7435211,"sourceType":"6","dataUrl":"dataUrl","flavorParamsIds":"0,487041,487071","plays":2,"views":3,"lastPlayedAt":1643277600,"width":1280,"height":720,"duration":3453,"msDuration":3453000,"id":"id","name":"GSN-LTT: Geothermal Engineering and Policy Support in Indonesia","description":"Over the past two years Arup has provided policy support to the\r\nIndonesian government to accelerate the development of geothermal power.&nbsp; In this talk, Mike Chendorain provides an overview of\r\ngeothermal engineering, financial planning of geothermal power projects, and\r\npolicy and stakeholder engagement aspects.<br>","partnerId":"","userId":"","creatorId":"","tags":"geothermal energy, indonesia","categories":"","categoriesIds":"","status":2,"moderationStatus":6,"moderationCount":0,"type":1,"createdAt":1495133675,"updatedAt":1556016025,"rank":0,"totalRank":0,"votes":0,"downloadUrl":"download url","searchText":"","licenseType":-1,"version":0,"thumbnailUrl":"thumbnailUrl","accessControlId":"","replacementStatus":0,"partnerSortValue":0,"conversionProfileId":7435211,"rootEntryId":"1_5gpxinot","operationAttributes":[],"entitledUsersEdit":"","entitledUsersPublish":"","entitledUsersView":"","capabilities":"","displayInSearch":1,"blockAutoTranscript":false,"objectType":"KalturaMediaEntry"}}

{
  "objectType": "KalturaMediaEntry",
  "name": "GSN-LTT: Geothermal Engineering and Policy Support in Indonesia",
  "description": "Over the past two years Arup has provided policy support to the\r\nIndonesian government to accelerate the development of geothermal power.\u0026nbsp; In this talk, Mike Chendorain provides an overview of\r\ngeothermal engineering, financial planning of geothermal power projects, and\r\npolicy and stakeholder engagement aspects.\u003cbr\u003e",
  "userId": "userId",
  "creatorId": "creatorId",
  "tags": "geothermal energy, indonesia",
  "categories": "",
  "categoriesIds": "",
  "type": "1",
  "licenseType": -1,
  "accessControlId": "",
  "partnerSortValue": 0,
  "conversionProfileId": "",
  "operationAttributes": {
    "-": ""
  },
  "entitledUsersEdit": "",
  "entitledUsersPublish": "",
  "entitledUsersView": "",
  "displayInSearch": 1,
  "blockAutoTranscript": false,
  "msDuration": 3453000,
  "mediaType": 1,
  "conversionQuality": "7435211",
  "sourceType": "6"
}

Which includes the data I wanted and the identical results in python. (The first two console logs are not printed by me, the library must have them somewhere).

Looking back I feel silly for not second-guessing the printing method, but we live and learn I guess.

Thank you again,
Hope you have a great weekend!

Jamie

Hi @Jamie ,

Glad to hear we’re good.
As to your request, yes, it could be beneficial to add a “pretty print” utility method to the various clients.
Not committing to an ETA but I’ll try to allocate some time for it in the near future:)

Cheers,