0

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.

Chris
  • 1,828
  • 6
  • 40
  • 108

2 Answers2

0

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']),
Chris
  • 1,828
  • 6
  • 40
  • 108
0

I had the same problem, and the solution I found is similar : The solution is to use %0A (which corresponds to a Line Feed) to add more entries.

curl -X POST 'https://api-free.deepl.com/v2/glossaries' \
-H 'Authorization: DeepL-Auth-Key [yourAuthKey]' \
-d 'name=My%20Glossary' \
-d 'source_lang=en' \
-d 'target_lang=de' \
-d 'entries=Hello%09Guten%20Tag%0AWord_1EN%09Word_01DE%0AWord_2EN%09Word_2DE' \
-d 'entries_format=tsv'

And if you are on Windows, you must make some changes to the structure:

curl -X POST "https://api-free.deepl.com/v2/glossaries" ^
-H "Authorization: DeepL-Auth-Key [yourAuthKey]" ^
-d "name=My%20Glossary" ^
-d "source_lang=en" ^
-d "target_lang=de" ^
-d "entries=Hello%09Guten%20Tag%0AWord_1EN%09Word_01DE%0AWord_2EN%09Word_2DE" ^
-d "entries_format=tsv"
Origami
  • 61
  • 1
  • 4