Language
Tools
Step 1: Obtain authorization
To subscribe to webhooks, you must first obtain client authorization via OAuth. You will be requesting these credentials on the behalf of your own application, so there will be no OAuth permissions dialog; you are only required to provide your client_id
and client_secret
.
To generate an application access token, you’ll need to initiate a POST request to https://sandbox.kopokopo.com/oauth/token
in our Sandbox environment or https://app.kopokopo.com/oauth/token
in our production environment. The request must include a Content-Type
header with the value of application/x-www-form-urlencoded
.
Example request
POST https://sandbox.kopokopo.com/oauth/token
Content-Type: application/x-www-form-urlencoded
client_id=CGQXLrlfuOqdUYdTcLz3rBiCZQDRvdWIUPkwasGMuGhkem9Bo&client_secret=g7QLwvO37aN2HoKx1amekWi8a2g7AIuPbD5CcJSLqXIcDOxfTr&grant_type=client_credentials
# Provide example using K2Connect https://github.com/kopo-kopo/k2-connect-python
import k2connect
k2connect.initialize(CLIENT_ID, CLIENT_SECRET, BASE_URL)
token_service = k2connect.Tokens
access_token_request = token_service.request_access_token()
access_token = token_service.get_access_token(access_token_request)
const options = {
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
apiKey: 'YOUR_API_KEY',
baseUrl: 'https://sandbox.kopokopo.com'
}
//Including the kopokopo module
var K2 = require("k2-connect-node")(options)
const TokenService = K2.TokenService
TokenService
.getToken()
.then(response => {
//Developer can decide to store the token_details and track expiry
console.log(response)
})
.catch( error => {
console.log(error)
})
# Provide example using K2Connect https://github.com/kopokopo/k2-connect-ruby
k2_token = K2AccessToken.new(CLIENT_ID, CLIENT_SECRET)
access_token = k2_token.request_token
<?
use Kopokopo\SDK\K2;
// Do not hardcode these values
$options = [
'clientId' => 'YOUR_CLIENT_ID',
'clientSecret' => 'YOUR_CLIENT_SECRET',
'apiKey' => 'YOUR_API_KEY',
'baseUrl' => 'sandbox.kopokopo.com'
]
$K2 = new K2($options);
// Get one of the services
$tokens = $K2->TokenService();
// Use the service
$result = $tokens->getToken();
if($result['status'] == 'success'){
$data = $result['data'];
echo "My access token is: ".$data['access_token'];
echo "It expires in: ".$data['expires_in'];
}
© 2024 Kopo Kopo, Inc.