Upload Config via REST API
While users can upload a config file via their Mona dashboards, some users might prefer doing this directly via our REST API and upload their config through there.
In order to upload the config, first of all, users must have an authorization token for their account.
More info on generating a token here.
Now, to upload the config users can leverage the /upload_config endpoint in the following way:
curl --location --request POST 'https://api{YOUR-USER-ID}.monalabs.io/upload_config' \
--header 'Authorization: Bearer {YOUR-ACCESS-TOKEN}'\
--header 'Content-Type: application/json' \
--data-raw '{
"config": {YOUR-CONFIG},
"commit_message": "YOUR-COMMIT-MESSAGE",
"author": "YOUR-USER-EMAIL"
}'
import requests
import json
url = "https://api{YOUR-USER-ID}.monalabs.io/upload_config"
payload = json.dumps({
"config": {YOUR-CONFIG},
"commit_message": "YOUR-COMMIT-MESSAGE",
"author": "YOUR-USER-EMAIL"
})
headers = {
'Authorization': 'Bearer {YOUR-ACCESS-TOKEN}',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
from mona_sdk.client import Client
api_key = <YOUR-API-KEY>
secret = <YOUR-SECRET>
my_mona_client = Client(api_key, secret)
my_mona_client.upload_config(
config=<YOUR-CONFIG>,
commit_message="YOUR-COMMIT-MESSAGE",
author="YOUR-USER-EMAIL"
)
Before uploading the config, Mona runs the config via a validation process. If the config is written incorrectly the endpoint will return the errors found in the config.
The successful response for this request will be the config, the config id and diffs if a previous config exists
{
"response_data": {
"new_config_id": "9180bf38-daae-493c-a7b4-c1b194e3b75b",
"new_config": {
"LOAN_APPLICATION_TUTORIAL": {
"fields": {
"occupation": {
"type": "string",
"function": "identity",
"args": [],
"tags": [
"metadata"
],
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"city": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"state": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"purpose": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"credit_score": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.02
}
}
},
"loan_taken": {
"type": "boolean",
"segmentations": {
"default": {
"default": true,
"type": "boolean",
"zero_values": [
false,
0
],
"one_values": [
true,
1
],
"zero_name": "False",
"one_name": "True"
}
}
},
"return_until": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1000000
}
}
},
"offered_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"approved_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"feature_0": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 60000
}
}
},
"feature_1": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.4
}
}
},
"feature_2": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 30
}
}
},
"feature_3": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 6000
}
}
},
"feature_4": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.01
}
}
},
"feature_5": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.2
}
}
},
"feature_6": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"feature_7": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1
}
}
},
"feature_8": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 50
}
}
},
"feature_9": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"stage": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"model_version": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"loan_paid_back": {
"type": "boolean",
"segmentations": {
"default": {
"default": true,
"type": "boolean",
"zero_values": [
false,
0
],
"one_values": [
true,
1
],
"zero_name": "False",
"one_name": "True"
}
}
}
},
"kapis": [
"credit_score",
"loan_taken",
"return_until",
"offered_amount",
"approved_amount",
"feature_0",
"feature_1",
"feature_2",
"feature_3",
"feature_4",
"feature_5",
"feature_6",
"feature_7",
"feature_8",
"feature_9",
"loan_paid_back"
]
}
}
},
"partial_data": false
}
Updated almost 2 years ago