-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPITest.py
More file actions
39 lines (32 loc) · 1.41 KB
/
Copy pathAPITest.py
File metadata and controls
39 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import requests
import os
from requests_ntlm import HttpNtlmAuth
from OpenOrchestrator.orchestrator_connection.connection import OrchestratorConnection
import json
orchestrator_connection = OrchestratorConnection("GOTest", os.getenv('OpenOrchestratorSQL'),os.getenv('OpenOrchestratorKey'), None)
API_url = orchestrator_connection.get_constant("GOApiTESTURL").value
go_credentials = orchestrator_connection.get_credential("GOTestApiUser")
session = requests.Session()
session.auth = HttpNtlmAuth(go_credentials.username, go_credentials.password)
payload = json.dumps({
"CaseTypePrefix": "GEO",
"MetadataXml": "<z:row xmlns:z=\"#RowsetSchema\" ows_Title=\"Case From Api Gustav\" ows_CaseStatus=\"Åben\" />",
"ReturnWhenCaseFullyCreated": True
})
headers = {
'Content-Type': 'application/json',
}
URL = API_url+"/geosager/_goapi/Cases"
response = session.post(URL, data=payload, headers=headers, timeout=500)
# Handle the response
if response.status_code == 200:
# Check if the response is JSON
if 'application/json' in response.headers.get('Content-Type', ''):
try:
print("Request successful:", response.json())
except json.JSONDecodeError:
print("Request successful, but response is not in JSON format:", response.text)
else:
print("Request successful, but response is not JSON:", response.text)
else:
print("Request failed:", response.status_code, response.text)