👋Webhook API

To access your struct via API you can use the Structize Websocket API.

You can access the Websocket API via wss://socket.structize.com

You will need an api_key and the id of your struct struct_id to use the webhook. These keys can be found in the Structize App.

Here is a short code example in both Python and JavaScript:

import websockets
import json
import time


async def test():
    uri = "wss://socket.structize.com"
    async with websockets.connect(uri) as websocket:
        await websocket.send(
            json.dumps(
                {
                    "api_key": "your_api_key",
                    "struct_id": "your_struct_id",
                    "text": "A text about a beautiful girl in a red dress",
                    "meta_data": {
                        "some_key": "your_optional_meta_data_you_want_in_the_repy_message",
                    }
                }
            )
        )

        try:
            start = time.time()
            # Continuously receive messages until server disconnects for max 15 minutes
            while time.time() < start + 910:
                message = await websocket.recv()
                print(message)
        except websockets.exceptions.ConnectionClosed:
            print("Connection closed by the server.")

await test()

If the authentication is successful you will first receive a success message:

{
  "status": "success",
  "message": "Authentication successful"
}

Once the authentication is successful, you will receive a message that we are processing your input and that the structizing has started:

{
  "status": "processing",
  "message": "Structizing the text..."
}

After about 10 seconds or up to several minutes for large structs you should receive the output in the following format:

{
  "status": "done",
  "struct": {
    "rationale": {
      "question_1_key": "rationale_for_the_answer_to_question_1",
      "question_2_key": "rationale_for_the_answer_to_question_2",
      ...
    },
    "question_1_key": answer_to_question_1,
    "question_2_key": answer_to_question_2,
    ...
  }
}

For more details you can check out our swagger on https://socket-docs.structize.com