Adding contracts to binders

Add contracts to binders by inserting contract ids or using search parameters.

Let's add some contracts to a binder!
There is two ways to approach this operation in Zefort API:

  1. Using a list of contract ids
  2. Using search parameters to choose contracts

1. Using a list of contract ids

So let's say we have a list of ids for contracts we want to bind to our binder. We can add it to our payload json and just like that, those contracts will be bound like nobody's business!

import requests

ZEFORT_APIKEY = 'ySLE1mhh6lfRsYa...'
BINDER_ID = 'bnd_1KkRayN40nouuVTujc'
CT_IDS = [
    "ct_1KmjVahd4Hg6W7l18c",
    "ct_1JXncwxR5skmpC4dDB"
]

response = requests.post(
    f'https://sandbox.zefort.com/api/binders/{BINDER_ID}/contracts/', 
    auth=(ZEFORT_APIKEY, ''),
    json={'contracts': CT_IDS})

print(response.json())

ZEFORT_APIKEY='ySLE1mhh6lfRsYa...'
BINDER_ID='bnd_1KkRayN40nouuVTujc'
CT_IDS='["ct_1Ka0utI1ZWqUwlljnA","ct_1KIdjQMAB9H3RvIuR3","ct_1Ki5qHWmY9KAuoGuSQ"]'

curl -X POST https://sandbox.zefort.com/api/binders/$BINDER_ID/contracts/ \
     -u $ZEFORT_APIKEY: \
     -H "Content-Type: application/json" \
     -d '{"contracts": '$CT_IDS'}'
Note: Curl command parsing is really quote-sensitive!

If you want to assign the list of contract ids to a variable, make sure to double quote the ids, and wrap the list in single quotes!
Otherwise your parsed -d will look like this:
-d {"contracts": [ct_1Ka0utI1ZWqUwlljnA,ct_1KIdjQMAB9H3RvIuR3,ct_1Ki5qHWmY9KAuoGuSQ]}

While it should look like this:
-d {"contracts": ["ct_1Ka0utI1ZWqUwlljnA","ct_1KIdjQMAB9H3RvIuR3","ct_1Ki5qHWmY9KAuoGuSQ"]}

2. Using search parameters to choose contracts

When you have hundreds of thousands of contracts, having to try and find the ids of all the contracts you want to bind would not be benefitical, so you can also use a search instead of id list.

In this example, the company has a few contracts named Searchable-named-contract-<number>, and they want to bind all of these to the same binder:

import requests

ZEFORT_APIKEY = 'ySLE1mhh6lfRsYa...'
BINDER_ID = 'bnd_1KkRayN40nouuVTujc'

response = requests.post(
    f'https://sandbox.zefort.com/api/binders/{BINDER_ID}/contracts/', 
    auth=(ZEFORT_APIKEY,''),
    json={
        'search': {"q": "Searchable-named-contr"}
    })

print(response.json())
ZEFORT_APIKEY="ySLE1mhh6lfRsYa..."
BINDER_ID="bnd_1KkRayN40nouuVTujc"

curl -X POST "https://sandbox.zefort.com/api/binders/$BINDER_ID/contracts/" \
     -u $ZEFORT_APIKEY: \
     -H "Content-Type: application/json" \
     -d '{"search": {"q": "Searchable-named-contr"}}'

Using the search parameter q means a string search, which tries to match your string to contracts' titles and text content. You can find more information on Zefort API queries here.

Response

Contract binding is a bulk operation. That means the request launches a task in Zefort API's back-end, and returns task information like this:

{
    "id": "task_1K8WmjFq1eqaeawrUi",
    "details": {"query_params": {},
                "data": {"search": 
                    {"q": "Searchable-named-contr"}}},
    "backend_status": "pending",
    "backend_status_info": "",
    "frontend_status": "pending",
    "description": "Contract Bulk operation"
}
If the operation considers a great lot of contracts, it may take some time to finish. You can check the up to date status of the task by polling it.