The create_question method allows you to programmatically create questions in your JupiterOne account. Questions are saved queries that can be run on-demand or on a schedule to monitor your infrastructure and security posture.
def create_question(
self,
title: str,
queries: List[Dict],
resource_group_id: str = None,
**kwargs
)-
title(str): The title of the question. This is required and cannot be empty. -
queries(List[Dict]): A list of query objects. At least one query is required. Each query object can contain:query(str, required): The J1QL query stringname(str, optional): Name for the query. Defaults to "Query{index}"version(str, optional): Query version (e.g., "v1")resultsAre(str, optional): Query result type. Defaults to "INFORMATIVE". Options include:- "INFORMATIVE" - Neutral information
- "GOOD" - Positive/expected results
- "BAD" - Negative/unexpected results
- "UNKNOWN" - Unknown state
resource_group_id(str): ID of the resource group to associate the question with
description(str): Description of the questiontags(List[str]): List of tags to apply to the questioncompliance(Dict): Compliance metadata containing:standard(str): Compliance standard namerequirements(List[str]): List of requirement IDscontrols(List[str]): List of control names
variables(List[Dict]): Variable definitions for parameterized queriesshowTrend(bool): Whether to show trend data for the question resultspollingInterval(str): How often to run the queries (e.g., "ONE_HOUR", "ONE_DAY")integrationDefinitionId(str): Integration definition ID if the question is integration-specific
Returns a dictionary containing the created question object with fields like:
id: Unique identifier for the questiontitle: The question titledescription: The question descriptionqueries: List of query objectstags: Applied tags- And other metadata fields
from jupiterone import JupiterOneClient
j1_client = JupiterOneClient(
account="your-account-id",
token="your-api-token"
)
# Create a simple question
question = j1_client.create_question(
title="Find All Open Hosts",
queries=[{
"query": "FIND Host WITH open=true",
"name": "OpenHosts"
}]
)# Create a question with multiple queries for comprehensive checks
question = j1_client.create_question(
title="Security Compliance Check",
queries=[
{
"query": "FIND Host WITH open=true",
"name": "OpenHosts",
"resultsAre": "BAD"
},
{
"query": "FIND User WITH mfaEnabled=false",
"name": "UsersWithoutMFA",
"resultsAre": "BAD"
},
{
"query": "FIND DataStore WITH encrypted=false",
"name": "UnencryptedDataStores",
"resultsAre": "BAD"
}
],
description="Comprehensive security compliance check",
tags=["security", "compliance", "audit"]
)# Create a question with all optional parameters
question = j1_client.create_question(
title="AWS Security Audit",
queries=[{
"query": "FIND aws_instance WITH publicIpAddress!=undefined",
"name": "PublicInstances",
"version": "v1",
"resultsAre": "INFORMATIVE"
}],
resource_group_id="resource-group-123",
description="Audit AWS instances with public IP addresses",
tags=["aws", "security", "network"],
showTrend=True,
pollingInterval="ONE_DAY",
compliance={
"standard": "CIS",
"requirements": ["2.1", "2.2"],
"controls": ["Network Security"]
},
variables=[
{
"name": "environment",
"required": False,
"default": "production"
}
]
)# Create a question with only required parameters
# The query name will default to "Query0" and resultsAre to "INFORMATIVE"
question = j1_client.create_question(
title="Simple Query",
queries=[{
"query": "FIND User LIMIT 10"
}]
)The method includes validation for required fields and will raise ValueError exceptions for:
- Missing or empty
title - Missing or empty
querieslist - Invalid query format (not a dictionary)
- Missing required
queryfield in query objects
try:
question = j1_client.create_question(
title="", # This will raise an error
queries=[]
)
except ValueError as e:
print(f"Error: {e}")The method uses the following GraphQL mutation internally:
mutation CreateQuestion($question: CreateQuestionInput!) {
createQuestion(question: $question) {
id
title
description
tags
queries {
name
query
version
resultsAre
}
# ... other fields
}
}