pythondeepl

DeepL API creating Glossary only creating with first entry


I am using the DeepL API and would like to create a glossary. I read followed the documentation and got a function to create a glossary like this:

def create_glossary():
    
    url = 'https://api-free.deepl.com/v2/glossaries'
    headers = {
        'Authorization': f'DeepL-Auth-Key {DEEPL_APY_KEY}'
    }
    
    data = {
        'name': 'Test Glossary',
        'source_lang': 'en',
        'target_lang': 'de',
        'entries': ['Yes,ja', 'Bye', 'Tschuess'],
        'entries_format': 'csv'
    }
    response = requests.post(url, headers=headers, data=data)
    print(response)
    if response.status_code == 201:
        glossary_id = response.json()['glossary_id']
        return glossary_id
    else:
        print('Error creating glossary:', response.json()['message'])

That function is creating a glossary but only with one entry.

What am I missing here? I obviously have two entries here: 'entries': ['Yes,ja', 'Bye', 'Tschuess'], but when checking the response, there is only the first one in the glossary.

What am I missing here? Couldn't find anything in the docs and support is not responding.


Solution

  • The issue with the entries parameter was that it expects the input in the form of a CSV string, where each entry is separated by a new line character (\n).

    This fixed it:

    'entries': '\n'.join(['Yes,ja', 'Bye,Tschuess']),