Skip to main content
Question

Get custom fields from API response?

  • November 1, 2024
  • 3 replies
  • 59 views

Forum|alt.badge.img+4

I am calling ‘/Job’ API with different offset and a 5000 limit to get all the backup jobs from commserve. However, I don’t need all the fields and only job status, id, time and a few others.

 

Is there any way I can limit the fields returned in the API?

3 replies

Forum|alt.badge.img+2
  • Byte
  • 6 replies
  • November 4, 2024

Hi @Prashant Mall 

While we may not have control over the API response, but we can parse it to suit our needs. 

 

Sample code in Python

---

import requests

import json

import pandas as pd

 

url = "https://<Webserver>/commandcenter/api/job"


 

payload={}

headers = {

  'Accept': 'application/json',

  'Authtoken': <TOKEN> //Replace with Token

}

 

response = requests.request("GET", url, headers=headers, data=payload,verify=False)

data = json.loads(response.text)

jobs_data = [(job['jobSummary']['jobId'], job['jobSummary']['status']) for job in data['jobs']]

df = pd.DataFrame(jobs_data,columns=['Job ID', 'Status'])

print(df)


---

 

jobs_data = [(job['jobSummary']['jobId'], job['jobSummary']['status']) for job in data['jobs']]

df = pd.DataFrame(jobs_data,columns=['Job ID', 'Status'])  : here you can add/remove column names according to your needs.


 

 


Forum|alt.badge.img+4

Hey! I am already doing that, but I am pulling all backup jobs and there are thousands of servers in our environment. The response payload is huge with many properties I really don’t need. It takes hours to collect the data and thus am wondering if there’s an option to set the properties I want in response of the APIs.


Forum|alt.badge.img+6
  • Vaulter
  • 30 replies
  • November 27, 2024

Hi Prashant,

 

An alternative option you could consider is creating a custom report or shared dataset that returns just the fields you want and use the /datasets API to retrieve the results. REST APIs for Reports


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings