For developers
Hand debts to Thwipe AI from your own software.
The Thwipe AI API lets your accounting or billing system, or an AI assistant working for you, do what you do on the website: connect or sign up, hand over your invoices, statements and spreadsheets, answer the questions, and start collecting. A sandbox lets you try it first without collecting anything.
How it works
Connect
The person presses Connect in your software, signs in or signs up on Thwipe AI’s own page, and presses Allow. Your software gets its keys at once: nobody copies a key or a code. An address that already has an account connects that business; no second account is made. Software with no person at a browser signs up with an emailed code instead.
Hand over files
Spreadsheets, invoices and statements, in any layout, in one request or a zip. They are read and checked exactly as files dropped on the website are.
Answer the questions
Anything the reading could not work out comes back as a question with its possible answers, the same choices the website offers.
Start collecting
Your software sends the person’s agreement to the sentence it was given, as the tick box on the website does. Attorneys run every collection from there.
The sandbox
Every business gets a practice copy, for trying its software without collecting anything. Files sent to the sandbox are really read and the questions really come up. When collection starts there, nobody is contacted, nothing is written to anyone and nothing is charged.
Keys and safety
- A key is shown once, when it is made. Only a fingerprint of it is kept, and it can be cancelled at any time.
- A key works for one business, with the access of the person who made it, and stops if that person leaves the business.
- The key goes in a request header, never in a web address. A key in an address is refused.
- The Connect page shows the person the web address their keys will go to. The code it hands back works once, within minutes, and only with a secret your software kept.
- Everything a key does is recorded under its name, for the business and the attorneys to see.
What it costs
The same as on the website: the attorneys collect, on the success fee on the Pricing page. There is nothing extra for using the API.
The instructions
Signed in, the same instructions are on Settings, then “Connect your own software”, where keys are made. Software can read them as plain text at /api/v1/docs.
The Thwipe AI API lets your own software do what you do on the website: connect or sign up, hand over your invoices, statements and spreadsheets, answer the questions, and start collecting. Your accounting system, your billing system or an AI assistant acting for you can use it. Everything it sends is read and checked exactly as files dropped on the website are.
Every request and answer is JSON, except files, which are sent as a form (multipart/form-data). Amounts are rand, written as text with two decimals: "1234.50".
1. Get your keys
An API key is a long secret that your software sends with every request, so Thwipe AI knows which business it is acting for. You always get two:
- a live key (it starts
live_) works on your business: what it starts is really collected; - a sandbox key (it starts
sandbox_) works on your sandbox, a practice copy of your business. See "The sandbox" below.
There are three ways to get them. Pick the first that fits.
The Connect button (for software a person uses)
Put a "Connect to Thwipe AI" button in your software. The person presses it, signs in or signs up on Thwipe AI's own page, presses Allow, and comes back to your software, which then has the keys. The person never copies a key and you never handle their sign-in code.
It follows the OAuth 2 standard (an authorization code with PKCE), so an OAuth library that supports PKCE should be able to do it for you; by hand it is the four steps below. There is nothing to register.
- Make a secret,
code_verifier: 43 to 128 random letters and digits. Keep it on your server. Itscode_challengeis the base64url SHA-256 of it:
code_verifier=$(openssl rand -base64 48 | tr -d '=+/' | cut -c1-64)
code_challenge=$(printf %s "$code_verifier" | openssl dgst -sha256 -binary | base64 | tr '+/' '-_' | tr -d '=')
- Send the person's browser to the Connect page:
https://thwipe.ai/connect?response_type=code&client_id=Your+Software+Name
&redirect_uri=https://yourapp.example/thwipe/back&state=<your own value>
&code_challenge=<code_challenge>&code_challenge_method=S256
client_id is your software's name, as the person will see it. redirect_uri is where the person comes back to:
it must start with https:// (or http://localhost while you build), and the page shows the person its address.
-
The person signs in (or signs up, with their name, the business's name and the terms tick) and presses Allow. Their browser comes back to
redirect_uri?code=<one-time code>&state=<your value>, or witherror=access_deniedif they said no. Check thatstateis the value you sent. -
Within 10 minutes, from your server, swap the code for the keys:
curl -X POST https://thwipe.ai/api/v1/connect/token \
--data-urlencode grant_type=authorization_code --data-urlencode code=<the code> \
--data-urlencode redirect_uri=https://yourapp.example/thwipe/back --data-urlencode code_verifier=<your code_verifier>
redirect_uri must be exactly the address you sent the person with. The answer's access_token is the live key,
and keys holds the live key and the sandbox key. A code works once. Connecting again from the same website (the
same host in redirect_uri, such as yourapp.example) gives new keys and cancels the ones it had there.
Signing up with the emailed code (for software with no person at a browser)
First, show the person the Terms and conditions and the Privacy notice, and note their versions:
curl https://thwipe.ai/api/v1/terms
Then ask for a code. Thwipe AI emails the person a six-digit code, the same one the website sends:
curl -X POST https://thwipe.ai/api/v1/sign-up/code \
-H 'Content-Type: application/json' \
-d '{"email": "owner@yourbusiness.co.za"}'
Ask the person for the code, and send it back with their name, the business's name and their agreement to the terms:
curl -X POST https://thwipe.ai/api/v1/sign-up \
-H 'Content-Type: application/json' \
-d '{"email": "owner@yourbusiness.co.za", "code": "123456", "your_name": "Thandi Mokoena",
"business_name": "Your Business (Pty) Ltd", "agree_to_terms": true,
"terms_version": "<from /api/v1/terms>", "privacy_version": "<from /api/v1/terms>"}'
The answer holds a live key and a sandbox key. If the email address already has an account, no new one is made: the
keys work on the business that already exists. If the person can start collecting for more than one business, the
answer lists them; ask for a new code and send it with "business_id" set to the one you want.
On the website
Already signed up? Make a key in Settings, under "Connect your own software", and copy it into your software.
Using a key
Send the key in the Authorization header of every request, never in the web address:
Authorization: Bearer live_your_key
A key is shown once, when it is made, and never again. Keep it as you would a password. If it may have been seen, cancel it in Settings, under "Connect your own software", and make a new one: a cancelled key stops working at once. A key acts with the access of the person who made it or pressed Allow, and stops working if that person is removed from the business. The person signs in to the website with the same email address and a code, whenever they like.
2. Hand over files
Send the spreadsheets, invoices and statements in one request, or a zip of them. They go into your open handover, or a new one:
curl -X POST https://thwipe.ai/api/v1/handovers \
-H "Authorization: Bearer $API_KEY" \
-F files=@debtors.xlsx -F files=@invoices.zip
The answer says which files were received (received) and gives the handover (handover, with its id). A
business has one open handover at a time, whether it was begun on the
website or here: files sent while one is open join it.
3. Check how it is going
curl https://thwipe.ai/api/v1/handovers/<id> -H "Authorization: Bearer $API_KEY"
Ask every few seconds while status is reading. Then status is one of:
questions: some debts wait on an answer (step 4). The others can start now;ready: nothing waits; you can start (step 5);starting, thencollecting: collection has started;cancelled.
The answer also says what was found (found), every debt and its state (accounts), the questions with their
possible answers, and, when you can start, the sentence the person agrees to by starting (start.sentence).
4. Answer the questions
Each question lists its possible answers. Send the one the person chose:
curl -X POST https://thwipe.ai/api/v1/handovers/<id>/questions/<question id> \
-H "Authorization: Bearer $API_KEY" -H 'Content-Type: application/json' \
-d '{"answer": "partly_paid", "amount": "1250.00"}'
Some answers need more, as their needs says:
amount: send"amount", in rand as text;note: send"note", a sentence;accounts: send"accounts", the ids of the debts picked fromchoices;contact: send"email","phone", or both;file: send the answer, then the document itself:
curl -X POST https://thwipe.ai/api/v1/handovers/<id>/questions/<question id>/file \
-H "Authorization: Bearer $API_KEY" -F file=@invoice-1042.pdf
5. Start collecting
Show the person start.sentence from step 3. When they agree, send:
curl -X POST https://thwipe.ai/api/v1/handovers/<id>/start \
-H "Authorization: Bearer $API_KEY" -H 'Content-Type: application/json' \
-d '{"agree": true}'
On your first handover the sentence includes the agreement for the attorneys to collect. Thwipe AI keeps the wording, the time, the internet address, the name your software gives for itself and the key, as it keeps the website's tick. Debts that still wait on an answer start by themselves once they are answered.
Only the business's owner can accept the agreement, so the first start needs a key the owner made.
Cancelling a handover
A handover that has not started can be cancelled. Its files are deleted:
curl -X POST https://thwipe.ai/api/v1/handovers/<id>/cancel -H "Authorization: Bearer $API_KEY"
The sandbox
The sandbox is a practice copy of your business, for trying your software without collecting anything. Use a sandbox key: it works only there, and a live key never does. Files sent to the sandbox are really read and the questions really come up. When you start collecting there, the debts show as collecting and stop: no letter is written, nobody is contacted, nothing is charged and nobody is emailed. You can look at the sandbox on the website from the API page.
Limits
- 120 requests a minute for each key;
- through the API, in any 24 hours: 2000 files and 1000 MB for your business, and 100 files and 100 MB for the sandbox;
- 3 sign-up codes for an email address an hour (on the Connect page too);
- a code from the Connect button works once, within 10 minutes;
- one request can be at most 500 MB, and must say its length (curl and HTTP libraries do);
- one file can be at most 100 MB, and a handover at most 2000 files; a zip is opened, and the files inside count.
Past a limit the answer's code is too_many or limit, and its message says when to try again.
Errors
Every error looks like this, with a code your software can act on and a sentence a person can read:
{"error": {"code": "not_ready", "message": "Handover is reading; it can be started once it has been read."}}
The codes: invalid (something in the request is missing or wrong), unauthorised (no key, or a key that does not
work), forbidden (the key's person may not do this), not_found, not_ready, wrong_code,
choose_business, conflict, too_many, limit, unavailable and server.
One address answers differently: /api/v1/connect/token uses OAuth's shape, so OAuth libraries understand it:
{"error": "invalid_grant", "error_description": "That code is wrong, has expired or has been used."}.