API Generate URL
Verifikasi Kehadiran pada Pelatihan Online
API Generate Oauth URL merupakan penerapan konsep verifikasi oAuth, di mana verifikasi dilakukan tidak disisi LP, namun di sisi Prakerja. Untuk itu, LP perlu meminta URL yang akan digunakan untuk memverifikasi peserta pelatihan, melalui API ini.
Dengan URL yang telah didapat, LP dapat mengarahkan (redirect) peserta ke URL tersebut untuk melakukan proses verifikasi selanjutnya.
Request
1curl --location 'https://api.prakerja.go.id/api/v1/integration/oauth/url-generate' \
2--header 'Content-Type: application/json' \
3--header 'client_code: CLIENT_CODE' \
4--header 'signature: SIGNATURE' \
5--header 'timestamp: TIMESTAMP_UNIX_IN_SECONDS' \
6--data '{
7 "redeem_code":"CODE_REDEEM",
8 "redirect_uri":"CALLBACK",
9 "email":"USER_EMAIL",
10 "sequence":SEQUENCE
11}'
Endpoint Path
Method
POSTHeader
Key | Value |
---|---|
Content-Type | application/json |
client_code | Unique Client ID yang disediakan Prakerja ke DP / LP. Prakerja akan menyediakan credential yaitu kombinasi client_code dan sign_key ke DP / LP. |
signature | Signature dibuat dari raw_signature yang di-hashing menggunakan algoritma HMAC-SHA1 dengan sign_key yang disediakan Prakerja ke DP / LP |
timestamp | Format nilai waktu dalam satuan detik yang digunakan saat melakukan hit API Contoh 1698289216 = 26-10-2023 10:00:16 WIB = 2023-10-26T10:00:16+07:00 Timestamp digunakan di --header 'timestamp:' yang nilainya harus sama persis dengan timestamp yang digunakan untuk membuat signature. |
Body (Payload)
Field | Type | Description |
---|---|---|
redeem_code | string, required | kode yang didapatkan oleh user prakerja ketika sukses membeli pelatihan. |
redirect_uri | string, required | URL Callback milik LP sesuai dengan isian di formulir ini. Setelah proses verifikasi selesai di Website Oauth akan dialihkan ke halaman ini. |
string, required | Email peserta yang terdaftar di Lembaga Pelatihan. Email tidak boleh digunakan lebih dari satu kali, untuk pelatihan yang sama. Namun diperbolehkan untuk pelatihan yang berbeda. Untuk validasi : 1 user/email di Lembaga Pelatihan tidak boleh membeli pelatihan yang sama | |
sequence | integer, optional | Menunjukan tahapan kehadiran
|
Response
Success Response
Response 200 OK
1{
2 "success": true,
3 "message": "OK",
4 "data": {
5 "url": "OAUTH_URL",
6 "state": "STATE",
7 "course": {
8 "type": 1,
9 "learning_method": "lms"
10 }
11 }
12}
Response Detail
Field | Type | Description |
---|---|---|
success | boolean | Status hit API,
|
message | string | Deskripsi status hit API |
error | string | Kode error di response API. Format ERRXXX |
data.url | string | LP harus mengalihkan user ke Oauth URL untuk proses verifikasi Liveness dan FR/Face Recognition Contoh Oauth URL: https://oauth.prakerja.go.id/consent?state=XYZ |
data.state | string | Merupakan kode unik untuk setiap sequence/urutan kehadiran peserta |
data.course.type | integer |
|
data.course.learning_method | string |
|
Error Response
- Termasuk juga list error general response
- Response 400 Bad Request redeem code not exist
1{ 2 "code": "ERRTRX40020", 3 "message": "Gagal verifikasi, kode tidak ditemukan", 4 "success": false 5}
- Response 400 Bad Request oauth sequence harus diisi
1{ 2 "code": "ERRPPA41014", 3 "message": "oauth sequence harus diisi", 4 "success": false 5}
- Response 400 Bad Request oauth redirect_uri harus diisi
1{ 2 "code": "ERRPPA41003", 3 "message": "oauth redirect_uri harus diisi", 4 "success": false 5}
- Response 400 Bad Request Email pengguna di LP harus diisi
1{ 2 "code": "ERRPPA41017", 3 "message": "Email pengguna di LP harus diisi", 4 "success": false 5}
- Response 400 Bad Request oauth redeem_code harus diisi
1{ 2 "code": "ERRPPA41006", 3 "message": "oauth redeem_code harus diisi", 4 "success": false 5}
- Response 400 Bad Request invalid redirect_uri / callback url
1{ 2 "code": "ERRPPA41008", 3 "message": "oauth callback tidak sesuai", 4 "success": false 5}
- Response 400 Bad Request callback url scheme harus https
1{ 2 "code": "ERRPPA42008", 3 "message": "oauth callback harus https", 4 "success": false 5}
- Response 400 Bad Request kode redeem sudah dibatalkan
1{ 2 "code": "ERRPPA41015", 3 "message": "kode redeem sudah dibatalkan", 4 "success": false 5}
- Response 400 Bad Request redeem/posttest sudah diverifikasi
1{ 2 "code": "ERRPPA41010", 3 "message": "redeem/posttest sudah diverifikasi", 4 "success": false 5}
- Response 400 Bad Request sesi/sequence belum mulai
1{ 2 "code": "ERRSCH40205", 3 "message": "Pertemuan pelatihan kamu belum dimulai. Silakan ikut pertemuan pelatihanmu pada %s WIB", 4 "success": false 5}
- Response 400 Bad Request sesi/sequence sudah selesai
1{ 2 "code": "ERRSCH41205", 3 "message": "Pertemuan pelatihan kamu sudah selesai pada %s WIB", 4 "success": false 5}
- Response 400 Bad Request redeem deadline
1{ 2 "code": "ERRSCH41206", 3 "message": "Kamu sudah melewati batas redeem.", 4 "success": false 5}
- Response 400 Bad Request Pelatihan tidak ditemukan
1{ 2 "code": "ERRTRX30004", 3 "message": "Pelatihan tidak ditemukan", 4 "success": false 5}
- Response 400 Bad Request Posttest gagal dikarenakan TPM belum lengkap
1{ 2 "code": "ERRSCH4058", 3 "message": "TPM belum lengkap, tidak bisa melakukan posttest.", 4 "success": false 5}
- Response 400 Bad Request Parameter request payload tidak valid. Silakan Cek required field dan tipenya
1{ 2 "code": "ERRPLT40018", 3 "message": "Parameter tidak valid.", 4 "success": false 5}
1// Generated by Prakerja Generator
2// for complete documentation please visit https://developer.prakerja.go.id
3
4const crypto = require('crypto-js');
5const axios = require('axios');
6
7const redeem_code = ''; // redeem code generated by system when user buy training
8
9const client_code = ''; // provided by Prakerja
10const timestamp = Math.round((new Date()).getTime() / 1000); // generate current timestamp
11const method = 'POST'; // API Method
12const endpoint = '/api/v1/integration/oauth/url-generate'; // API Redeem Status Endpoint
13
14const data = {};
15
16const input = client_code + timestamp + method + endpoint + JSON.stringify(data); // create signature input
17const sign_key = ''; // provided by Prakerja
18
19const signature = crypto.HmacSHA1(input, sign_key).toString(crypto.enc.Hex); // generate signature
20
21axios({
22method: 'post',
23url: 'https://api.prakerja.go.id' + endpoint,
24headers: {
25 'Content-Type': 'application/json',
26 'client_code': client_code,
27 'signature': signature,
28 'timestamp': timestamp
29},
30data
31})
32.then((response) => {
33console.log(response.data)
34})
35.catch((error) => {
36console.log(error.response.data)
37});
1<?php
2// Generated by Prakerja Generator
3// for complete documentation please visit https://developer.prakerja.go.id
4
5$redeem_code = ''; // redeem code generated by system when user buy training
6
7$client_code = ''; // provided by Prakerja
8$timestamp = time(); // generate current timestamp
9$method = 'POST'; // API Method
10$endpoint = '/api/v1/integration/oauth/url-generate'; // API Redeem Status Endpoint
11
12$data = [];
13
14$input = $client_code . $timestamp . $method . $endpoint . json_encode($data); // create signature input
15$sign_key = ''; // provided by Prakerja
16
17$signature = hash_hmac('sha1', $input, $sign_key); // generate signature
18
19$headers = [
20'Content-Type: application/json',
21'client_code: ' . $client_code,
22'signature: ' . $signature,
23'timestamp: ' . $timestamp,
24];
25
26$ch = curl_init();
27curl_setopt($ch, CURLOPT_URL, 'https://api.prakerja.go.id' . $endpoint );
28curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29curl_setopt($ch, CURLOPT_POST, 1);
30curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
31curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
32$result = curl_exec($ch);
33curl_close ($ch);
34
35print_r("result: ");
36print_r($result);
1# Generated by Prakerja Generator
2# for complete documentation please visit https://developer.prakerja.go.id
3
4from hashlib import sha1
5import hmac
6import time
7import json
8import requests
9
10redeem_code = '' # redeem code generated by system when user buy training
11
12client_code = '' # provided by Prakerja
13timestamp = str(int(time.time())) # generate current timestamp
14method = 'POST' # API Method
15endpoint = '/api/v1/integration/oauth/url-generate' # API Redeem Status Endpoint
16
17data = {}
18
19# create signature input
20input = client_code + timestamp + method + endpoint + json.dumps(data, separators=(',', ':'))
21
22sign_key = '' # provided by Prakerja
23
24# generate signature
25signature = hmac.new(sign_key.encode("utf-8"), input.encode("utf-8"), sha1).hexdigest()
26
27headers = {
28'Content-Type': 'application/json',
29'client_code': client_code,
30'signature': signature,
31'timestamp': timestamp
32}
33
34result = requests.post(
35'https://api.prakerja.go.id' + endpoint,
36headers=headers,
37data=json.dumps(data)
38)
39
40print('result: ')
41print(result.text)
1# Generated by Prakerja Generator
2# for complete documentation please visit https://developer.prakerja.go.id
3
4require 'base64'
5require 'cgi'
6require 'openssl'
7require 'net/http'
8require 'uri'
9require 'json'
10
11redeem_code = '' # redeem code generated by system when user buy training
12
13client_code = '' # provided by Prakerja
14timestamp = String(Time.now.to_i) # generate current timestamp
15method = 'POST' # API Method
16endpoint = '/api/v1/integration/oauth/url-generate' # API Redeem Status Endpoint
17
18data = {}
19
20# create signature input
21input = client_code + timestamp + method + endpoint + JSON.generate(data, quirks_mode: true)
22
23key = '' # provided by Prakerja
24
25signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), key.encode("ASCII"), input.encode("ASCII"))
26
27uri = URI.parse('https://api.prakerja.go.id' + endpoint)
28request = Net::HTTP::Post.new(uri)
29request.content_type = "application/json"
30request.body = JSON.generate(data, quirks_mode: true)
31request['Client_code'] = client_code
32request['Signature'] = signature
33request['Timestamp'] = timestamp
34
35req_options = {
36use_ssl: uri.scheme == "https",
37}
38
39result = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
40http.request(request)
41end
42
43# result.code
44# result.body
45puts 'result: ' + result.body