copyfactory.io
  • Getting started
    • Overview
      • Authentication
      • Rate limiting
      • Errors
  • API
    • Playbooks
      • The playbook object
      • List playbooks
    • Sequences
      • The sequence object
      • List sequences
    • Contacts
      • The contact object
      • Create contact
      • Get contact
      • Search contacts
    • Profiles
      • The profile object
      • Get a profile
      • List all profiles
    • Premises
      • The premise object
      • Get a premise
      • List all premises
    • Generations
      • The generations object
      • Generate text
  • Text Generation Tutorials
    • How to generate text
  • App
    • Website
    • Login
Powered by GitBook
On this page
  1. Text Generation Tutorials

How to generate text

This article explains how to start generating personalized sentences for your contacts.

PreviousGenerate text

Last updated 2 years ago

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

  1. 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.

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 or ''. 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.

'list all premises'
get premise' endpoints
Generate text