Skip to content

First Request

Languages

Below are examples of requests to an API using different programming languages:

NodeJs - Request

var request = require("request");
var options = {
	method: "POST",
	url: "https://api.lettria.com/structuration",
	headers: {
		Authorization: "LettriaProKey API_TOKEN",
		"Content-Type": "application/json",
	},
	body: JSON.stringify({
		documents: ["hello"],
	}),
};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

Python - Requests

import requests
import json

url = "https://api.lettria.com/structuration"

payload = json.dumps({
  "documents": [
    "The text to process"
  ]
})
headers = {
  'Authorization': 'LettriaProKey API_TOKEN',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

cURL

curl --location --request POST 'https://api.lettria.com/structuration' \
--header 'Authorization: LettriaProKey ${API_TOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "documents": [****
       "First document to analyse"
    ]
}'

Examples

Get card attributes

Get all attributes of a card from a document.

import requests

def getLettriaAnalysis(document):
	rq = requests.post(
		"https://api.lettria.com/structuration",
		json = {
			"documents": [document]
		},
		headers = {
			"Authorization": "LettriaProKey $API_TOKEN",
			"Content-Type": "application/json"
		})
	res = rq.json()
	return res

def get_card_attribute(document, lemma):
	data = getLettriaAnalysis(document)
	attributes = []
	for document in data:
		for card in document['cards']:
			if card['lemma'] == lemma:
				attributes.append(card['attributes'])
	return attributes

Next step