#
Calling Endpoints
The format of the endpoint URL depends on whether it is restricted or unrestricted.
- Unrestricted:
{workspace-url}/api/endpoints/external/{path} - Restricted:
{workspace-url}/api/endpoints/token/run/{path}
#
Using curl
curl -X POST -H "Authorization: Bearer YOUR_TOKEN" \
-d '{"key": "value"}' \
http://localhost:8080/api/endpoints/token/run/my-endpoint
#
From a Data Connector (C#)
var client = new EndpointsClient("http://localhost:8080/", token);
var response = await client.CallAsync<string>("my-endpoint", "my-body");
#
From the Front-End (C# / h5)
var response = await Mosaik.API.Endpoints.CallAsync<string>("my-endpoint");
#
Long-running (Pooling) Endpoints
For pooling endpoints, if the execution of the endpoint takes more than a few seconds, you will receive a 202 Accepted status code. This indicates the task is still in progress.
When you receive a 202 Accepted, you should:
- Wait for a few seconds.
- Retry the exact same request (including the same body).
- Optionally, use the value returned in the
MSK-ENDPOINT-KEYheader to retry the request without passing the same request body again (by including it as a header in subsequent calls).
The built-in EndpointsClient (C#) and Mosaik.API.Endpoints (front-end) handle this logic automatically.
#
Calling from outside Curiosity (Python)
If you are calling a pooling endpoint from an external system using Python, you can implement the following retry logic:
import requests
import time
def call_curiosity_endpoint(url, payload, token=None, max_retries=100, retry_delay=5):
headers = {'Content-Type': 'application/json'}
if token:
headers['Authorization'] = f'Bearer {token}'
attempt = 0
msk_endpoint_key = None
while attempt < max_retries:
if msk_endpoint_key:
# Once we have a key, we can use it to poll without sending the payload again
headers['MSK-ENDPOINT-KEY'] = msk_endpoint_key
response = requests.post(url, headers=headers)
else:
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 202:
print(f"Processing... retrying in {retry_delay} seconds")
msk_endpoint_key = response.headers.get('MSK-ENDPOINT-KEY')
time.sleep(retry_delay)
attempt += 1
elif response.status_code == 200:
return response.json()
else:
response.raise_for_status()
raise TimeoutError("Endpoint did not return a final response after max retries")
# Example usage
if __name__ == "__main__":
workspace_url = "https://your-workspace.curiosity.ai"
endpoint_path = "long-running-task"
token = "your-jwt-endpoint-token"
url = f"{workspace_url}/api/endpoints/token/run/{endpoint_path}"
payload = {"query": "Find similar support cases"}
try:
result = call_curiosity_endpoint(url, payload, token=token)
print("Final result:", result)
except Exception as e:
print("Error:", e)