# How to generate text

In order to generate text using the API today you will need two pieces of information:

1. &#x20;The sentence premise ID
2. A dictionary of variables that contain contact data if you are generating a sentence or the inputs if you are generating an email.

The example below will illustrate the process for generating a **sentence premise** however the process is the same for email generation.

{% hint style="info" %}
Premises can only be created in your dashboard.
{% endhint %}

Let's start by grabbing our sentence ID.

You can filter for sentence premise IDs by using the ['list all premises'](https://developers.copyfactory.io/api/premises/list-all-premises) or '[get premise' endpoints](https://developers.copyfactory.io/api/premises/get-a-premise)'. This is what the object returned will look like.

```
# Sentence premise object
{
    "data": {
        "id": 19,
        "premise_name": "Contact",
        "required_variables": [
            "person_description", "first_name"
        ],
        "profile_name": "Copyfactory"
        "premise_type": "sentence"
    }
}
```

The 'required variables' key contains an array of fields that need data for this sentence premise to generate.

```
"required_variables": ["person_description", "first_name"],
```

In the example above we would therefore need to create a dictionary with the keys 'person\_descriptio&#x6E;*'* and *'*&#x66;irst\_name' where the values are the contact data inputs.

```
{
	"first_name": "Mark",
	"person_description": "This is my description of someone..."
}
```

Once we have these two pieces of information the last step is to make a POST request to the generate sentence endpoint.

An example in python could look like this:

```
import requests
import json

url = "https://app.copyfactory.io/api/v2/generate/"

payload = json.dumps({
  "premise_id": 19, # taken from sentence premise ID above
  "variables": {
    "first_name": "Mark",
    "person_description":"This is my description of someone..."
  }
})

headers = {
  'Authorization': 'API-KEY',
  'Content-Type': 'application/json'
}

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

print(response.text)
```

{% hint style="info" %}
If you get an error try looking at the meta data to see the related objects.
{% endhint %}

And you are done!

Consult the text generation object by going to the link below.

{% content-ref url="../api/generations/generate-text" %}
[generate-text](https://developers.copyfactory.io/api/generations/generate-text)
{% endcontent-ref %}
