Links

How to generate text

This article explains how to start generating personalized sentences for your contacts.
In order to generate text using the API today you will need two pieces of information:
  1. 1.
    The sentence premise ID
  2. 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.
Premises can only be created in your dashboard.
Let's start by grabbing our sentence ID.
You can filter for sentence premise IDs by using the 'list all premises' or 'get premise' endpoints'. 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_description' and 'first_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)
If you get an error try looking at the meta data to see the related objects.
And you are done!
Consult the text generation object by going to the link below.
Last modified 1yr ago