python-requestszoho

What does it mean when Zoho Sign's create document API method returns an "Extra key found" error message?


I'm using the Python requests library to implement the Zoho Sign document creation method shown here: https://www.zoho.com/sign/api/document-managment/create-document.html

I'm using the following code:

import requests

requests.post('https://sign.zoho.com/api/v1/requests', {
    'requests': {
        'request_name': 'My Signing Request',
        'expiration_days': 18,
        'email_reminders': True,
        'reminder_period': 5,
        'notes': '',
        'is_sequential': True,
        'actions': ACTION_ARRAY,
    }
}, files={
    'file': FILE_IN_BYTES
})

Instead of a success response, I get the following error:

{"code":9015,"error_param":"requests","message":"Extra key found","status":"failure"}

Not sure what's going on here, as I'm passing their sample data in my request, and it doesn't seem to recognize it. I've tried passing the data as json via "json=", which silences the error, but then everything I pass over is ignored. Any ideas?


Solution

  • So as it turns out, Zoho Sign requires a mish-mash of formats in order for the request data to register correctly, which is not entirely clear from the documentation. The following will result in a successful call:

    import json
    import requests
    
    requests.post('https://sign.zoho.com/api/v1/requests', {
        'data': json.dumps({'requests': {
            'request_name': 'My Signing Request',
            'expiration_days': 18,
            'email_reminders': True,
            'reminder_period': 5,
            'notes': '',
            'is_sequential': True,
            'actions': ACTION_ARRAY,
        }})
    }, files={
        'file': FILE_IN_BYTES
    })
    

    Because the file must be sent as multipart-encoded form data, everything else has to be fit into the "data" field as json-encoded data. Submitting it as non-json-encoded data will result in an error.

    So to answer the original question, the reason for the "Extra key found" message is that Zoho is expecting to receive a "data" key and only a "data" key containing the request data. When it saw the "requests" key instead, this registered as an extra and unwanted key. Hence the message.