Unexpected token API error

I’m trying to use Python to create a note from an email received. Creating the note works with:

curl_command = 'curl --data \'{ "title": "' + sUB + '", "body": "' + Final_body + '", "parent_id": "' + joplin_inbox_folder + '" }\' http://localhost:41184/notes?token=' + joplin_token
os.system(curl_command)

if Final_body just contains a simple piece of text that I’ve inserted into it. But if I use a real email the note isn’t created and log_clipper.txt shows:

2019-06-07 16:31:39: "Request: POST /notes?token=[my joplin token]"
2019-06-07 16:31:39: "SyntaxError: Unexpected token 
 in JSON at position 75
SyntaxError: Unexpected token 
 in JSON at position 75
    at JSON.parse (<anonymous>)
    at Api.action_notes (/tmp/.mount_JoplinAvIN0i/resources/app/lib/services/rest/Api.js:362:29)
    at Api.route (/tmp/.mount_JoplinAvIN0i/resources/app/lib/services/rest/Api.js:120:42)
    at execRequest (/tmp/.mount_JoplinAvIN0i/resources/app/lib/ClipperServer.js:147:39)
    at IncomingMessage.request.on (/tmp/.mount_JoplinAvIN0i/resources/app/lib/ClipperServer.js:190:8)
    at IncomingMessage.emit (events.js:182:13)
    at endReadableNT (_stream_readable.js:1092:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)"

Sometimes the Python program also says Unexpected token \n in JSON at position 75

I’m not a Python programmer and know very little about Ubuntu, where I’m running this, but if anyone has the time to point me in the right direction I’d appreciate it.

You can just use curl

curl --data '{ "title": "test2 title", "body": "test2 body", "parent_id": "id grab fom the folders list" }' http://localhost:41184/notes?token=<the token found in the webclipper config page>

if you really want to use python, avoid os.system and try https://3.python-requests.org/

Thanks, but I think I need to use Python as that’s how I’m getting the email messages using POP3.

Not using Python, on the command line, this works (with \n):

curl --data ‘{ “title”: “This is the title”, “body”: “This is \nthe body”, “parent_id”: “ff1adf379ebd43d092b0e008580a6402” }’ http://localhost:41184/notes?token= ```

In Python, without \n, this works:

test_body = “This is the body.”
params = ((‘token’, joplin_token),)
data = ‘{“title”: "’ + sUB + ‘", “body”: "’ + test_body + ‘", “parent_id”: "’ + joplin_inbox_folder + ‘" }’
response = requests.post(‘http://localhost:41184/notes’, params=params, data=data)

But with

test_body = “This is \nthe body.”

it doesn’t work.

Looks like it’s something to do with Python, or the way I’m using it.

I use python requests extensively with the joplin api, you should definitely check out the link @foxmask.