This guide provides a step-by-step process for creating use cases and posting evidence through the Credo AI API. It assumes the use of environment variables for configuration and relies on Python and the requests library to interact with the API. For more details on the endpoint, see our swagger documentation.
Note:
- Self-hosted customers must replace
https://api.credo.ai
with your Credo AI URL ${TENANT}
is the tenant name used to log in to Credo AI- See Authentication for how to get the required
${ACCESS_TOKEN}
Step 1: Create a new use case in Credo AI.
- Body params
name
→ Use case name must be uniquedescription
→ Use case description
import requests
url = "https://api.credo.ai/api/v2/${TENANT}/use_cases"
headers = {
"content-type": "application/vnd.api+json"
"Authorization": "Bearer ${ACCESS_TOKEN}"
}
payload = {
"data": {
"attributes": {
"ai_type": "string",
"description": "string",
"icon": "string",
"industries": [
"Fishing, Hunting, & Trapping"
],
"is_vendor": true,
"monetary_value": 0,
"name": "string",
"owner": {
"owner_id": "user_id",
"owner_type": "user"
},
"questionnaire_ids": [
"SEQR+1",
"PRIV+2"
],
"regions": [
"CA",
"US"
],
"risk_classification_level": 1
},
"type": "resource-type"
}
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
Step 2: Retrieve the data for the questionnaire that is linked to the created use case.
Note: When a questionnaire gets linked to a use case a relational section id is created linking the specific questionnaire with the use case
- URL params
use_case_id
→ returned from step 1
- The response contains a
section_id
and anid
. Thesection_id
is the default id for the sections in a questionnaire. The id is the relational id for this version of the questionnaire that has been linked to the use case - The response also contains the
question_id
which is used for posting evidence in the next step
import requests
url = "https://api.credo.ai/api/v2/${TENANT}/use_cases/{use_case_id}/questionnaire_sections"
headers = {
"content-type": "application/vnd.api+json"
"Authorization": "Bearer ${ACCESS_TOKEN}"
}
response = requests.get(url, headers=headers)
print(response.text)
Step 3: Post evidence data for each question within each section of the use case's questionnaire.
- URL params:
use_case_id
→ returned from step 1use_case_section_id
is the relational section id from step 2
- Body params
question_id
in the body from step 2
import requests
url = "https://api.credo.ai/api/v2/${TENANT}/use_cases/{use_case_id}/questionnaire_sections/{use_case_section_id}/evidences"
headers = {
"content-type": "application/vnd.api+json"
"Authorization": "Bearer ${ACCESS_TOKEN}"
}
payload =
{
"data": {
"attributes": {
"data": {
"value": "This is text evidence"
},
"generated_at": "2022-05-03T11:33:25.582138Z",
"question_id": "string"
},
"type": "resource-type"
}
}
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)