Create Token

Create Token After Login

Setelah peserta login di halaman Prakerja, akan diarahkan kembali ke halaman LP, sesuai dengan parameter redirect_uri dan login_uri yang diberikan LP pada API Generate URL. Ketika di redirect, sistem Prakerja akan menambahkan parameter code di URL, yang kita perlukan untuk membuat access token, contoh: http://domainkamu.com/createtoken?code=XYZ, maka code yang diperlukan adalah XYZ.

Request

1curl --location 'https://api-proxy.prakerja.go.id/api/v1/oauth/token' \
2--header 'X-Client-Id: CLIENT_CODE'
3--data '{
4  "code": "CODE"
5}'
Endpoint Path
Method
POST
Header
KeyValue
X-Client-IdUnique Client ID yang disediakan Prakerja ke DP / LP.
Prakerja akan menyediakan credential yaitu kombinasi client_code dan sign_key ke DP / LP.
Query Params
FieldTypeDescription
codestring, requiredDidapatkan dari query parameter pada URL redirect_uri

contoh: http://domainkamu.com/createtoken?code=XYZ, maka code yang diperlukan adalah XYZ.

Response

Success Response

Response 200 OK

1{
2  "message": "no error",
3  "success": true,
4  "errorCode": "0",
5  "data": {
6    "access_token": "TOKEN",
7    "expires_in": "TIMESTAMP",
8    "refresh_token": "REFRESH_TOKEN",
9    "scope": "SCOPE",
10    "token_type": "Bearer"
11  }
12}

Response Detail

FieldTypeDescription
messagestringDeskripsi status hit API
successbooleanStatus hit API,
  • true : sukses
  • false : gagal
errorCodestringKode error di response API. Format ERRXXX
data.access_tokenstringToken yang dihasilkan, nantinya digunakan untuk mengakses API lainnya.
data.expires_instringWaktu expired Token, dalam format timestamp satuan detik.
data.refresh_tokenstringDigunakan untuk membuat Acces Token baru yang expired, tanpa harus login kembali.
data.scopestringScope data yang dapat diakses, sesuai SCOPE yang diminta saat Generate URL.
data.token_typestringTipe token.
Error Response
  • Termasuk juga list error general response
  • Response 400 Bad Request NotFoundContextClientId
    1{
    2  "code": "ERROAUTH4024",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthClientIdNotFound
    1{
    2  "code": "ERROAUTH4029",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request NotFoundContextUserId
    1{
    2  "code": "ERROAUTH4030",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthAuthCodeNotFound
    1{
    2  "code": "ERROAUTH4031",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthAuthCodeNotSame
    1{
    2  "code": "ERROAUTH4032",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrScopeNotMatch
    1{
    2  "code": "ERROAUTH4033",
    3  "message": "scope tidak sesuai",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureTimestampNotInteger
    1{
    2  "code": "ERROAUTH4034",
    3  "message": "timestamp harus integer",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureTimestampValueGreaterThanServerNow
    1{
    2  "code": "ERROAUTH4035",
    3  "message": "timestamp melebihi waktu server",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureExpired
    1{
    2  "code": "ERROAUTH4036",
    3  "message": "Signature expired",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignaturePayloadInvalidJSON
    1{
    2  "code": "ERROAUTH4037",
    3  "message": "Signature payload invalid JSON",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureNotMatch
    1{
    2  "code": "ERROAUTH4038",
    3  "message": "Signature not match",
    4  "success": false
    5}
  • Response 400 Bad Request ErrMissingSignature
    1{
    2  "code": "ERROAUTH4039",
    3  "message": "Signature not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrMissingTimestamp
    1{
    2  "code": "ERROAUTH4040",
    3  "message": "Timestamp not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrMissingMethod
    1{
    2  "code": "ERROAUTH4041",
    3  "message": "Method not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrGrantTypeNotMatch
    1{
    2  "code": "ERROAUTH4042",
    3  "message": "grant_type tidak sesuai",
    4  "success": false
    5}
  • Response 400 Bad Request ErrRefreshTokenKeyNotFound
    1{
    2  "code": "ERROAUTH4043",
    3  "message": "Refresh token key not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrValidationInput
    1{
    2  "code": "ERROAUTH4044",
    3  "message": "Input tidak valid",
    4  "success": false
    5}
  • Response 400 Bad Request ErrRedirectUriNotValid
    1{
    2  "code": "ERROAUTH4045",
    3  "message": "Redirect URI not valid",
    4  "success": false
    5}
  • Response 400 Bad Request ErrLoginUriNotValid
    1{
    2  "code": "ERROAUTH4046",
    3  "message": "Login URI not valid",
    4  "success": false
    5}
  • Response 400 Bad Request ErrValidateJWTAuthCode
    1{
    2  "code": "ERROAUTH4047",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrValidateJWTToken
    1{
    2  "code": "ERROAUTH4048",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrCreateJWTToken
    1{
    2  "code": "ERROAUTH4049",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrJWTSignKeyNotMatch
    1{
    2  "code": "ERROAUTH4050",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrTokenExpired
    1{
    2  "code": "ERROAUTH4051",
    3  "message": "Token expired",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthAuthCodeExpired
    1{
    2  "code": "ERROAUTH4052",
    3  "message": "Auth code expired",
    4  "success": false
    5}
  • Response 400 Bad Request ErrTokenNotFoundHeader
    1{
    2  "code": "ERROAUTH4053",
    3  "message": "Token not found",
    4  "success": false
    5}
Try this API
 
Example Code
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 client_code = "";
8const method = "POST";
9const url = "https://api.prakerja.go.id/api/v1/oauth/token";
10const headers = {
11  "X-Client-Id": client_code,
12};
13const data = JSON.stringify({
14  code: "",
15});
16
17axios({
18  method,
19  url,
20  headers,
21  data,
22})
23.then((response) => {
24  console.log(response.data)
25})
26.catch((error) => {
27  console.log(error.response.data)
28});
1<?php
2// Generated by Prakerja Generator
3// for complete documentation please visit https://developer.prakerja.go.id
4
5$client_code = "";
6$method = "POST";
7$url = "https://api.prakerja.go.id/api/v1/oauth/token";
8$headers = [
9  "X-Client-Id: " . $client_code,
10];
11$data = [
12  'code' => "",
13];
14
15$ch = curl_init();
16curl_setopt($ch, CURLOPT_URL,            $url );
17curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
18curl_setopt($ch, CURLOPT_POST,           1);
19curl_setopt($ch, CURLOPT_HTTPHEADER,     $headers);
20curl_setopt($ch, CURLOPT_POSTFIELDS,     json_encode($data));
21$result = curl_exec($ch);
22curl_close ($ch);
23
24print_r("result: ");
25print_r(json_decode($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
10client_code = ""
11method = "POST"
12url = "https://api.prakerja.go.id/api/v1/oauth/token"
13headers = {
14  "X-Client-Id": client_code,
15}
16data = {
17  'code': '',
18}
19
20result = requests.post(
21  url,
22  headers=headers,
23  data=json.dumps(data)
24)
25
26print('result: ')
27print(json.loads(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
11client_code = ""
12url = "https://api.prakerja.go.id/api/v1/oauth/token"
13data = {
14  'code': '',
15}
16
17uri = URI.parse(url)
18request = Net::HTTP::Post.new(uri)
19request.content_type = "application/json"
20request['X-Client-Id'] = client_code
21request.body = JSON.generate(data, quirks_mode: true)
22
23req_options = {
24  use_ssl: uri.scheme == "https",
25}
26
27result = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
28http.request(request)
29end
30
31# result.code
32# result.body
33puts 'result: '
34puts JSON.parse(result.body)