Get Auth Code API

Path/{version}/get-auth-code
HTTP MethodGET
Versionv1.0
SNAP service code10

📘

To simplify the integration, we highly recommends merchant to call this Get Auth Code API directly from merchant's front end.

📘

We are deprecating request and respone header from the Get Auth Code API. Moving forward merchant is not required to pass request header as part of the Get Auth Code API call.

For merchant that has already passed the headers, we will maintain the backward compatibality and process the API call as is.

Request Header

Field NameField TypeMandatoryField Description
Content-typeStringMMedia type of the resource, i.e. application/json.
X-TIMESTAMPStringMClient’s current local time in ISO-8601 format.
X-SIGNATUREStringMCreated using symmetric signature HMAC_SHA512 algorithm.
AuthorizationStringMRepresents access_token of a request; string starts with keyword “Bearer ” followed by access_token. Can get this token from Access Token B2B API response.
X-PARTNER-IDStringMUnique identifier for merchant. Provided by Midtrans.
X-EXTERNAL-IDStringMNumeric string. Reference number that should be unique in the same day or 1 day idempotency key.
CHANNEL-IDStringMMandatory field from Bank Indonesia that can take any value with correct format 5 digits numeric string
Content-type:application/json
X-TIMESTAMP:2024-03-19T14:30:00+07:00
X-SIGNATURE: da1fa417c72d6b91c257e01e54fac824
Authorization: Bearer gp9HjjEj813Y9JGoqwOeOPWbnt4CupvIJbU1Mmu4a11MNDZ7Sg5u9a
X-PARTNER-ID: G123456
X-EXTERNAL-ID:12345678901234567890
CHANNEL-ID:12345

Query Parameter

Field NameField TypeMandatoryField Description
redirectURLString (256) MMerchant callback URL after success get auth code. Need to be whitelisted from GoPay side (part of GoPay Tokenization onboarding process).
scopesList of String (256)MAccess scope from authorization. Possible value = DEFAULT.
stateString (32)MRandom string for CSRF.
merchantIdString (64)MMerchant payment handle, merchant identifier in UUID format. Provided by Midtrans.
Note: this value is not Midtrans Merchant ID, but a different value, here's the sample format: 303b4f89-xxxx-xxxx-xxxx-62a8ffaefaf3

The value on staging and production is different. Please make sure that you are sending the correct value based on the environment that you are using.
langString(2)MLanguage code for service
Possible values: en, id.
seamlessDataString (512)MData to speed up the validation and verification process.
seamlessData.mobileNumberStringMMobile number to be linked (format should be country code (without "+") + phone number. Example: 62812345678).
seamlessData.paymentTypeStringMPayment type to be linked. Possible value: gopay.
seamlessSignString (512)MSignature from seamlessData.
/get-auth-code?state=<RANDOM_UNIQUE>&merchantId=<merchant-id>&lang=id&scopes=DEFAULT&redirectUrl=<MERCHANT_OAUTH_CALLBACK_URL>&seamlessData=<SEAMLESS_DATA>&seamlessSign=<SIGNATURE>
Seamless Data Format
seamlessData = URLEncode("mobileNumber=62822999999&paymentType=gopay")
Seamless Sign Format
seamlessSign = URLEncode(Base64(SHA256withRSA(privateKey, seamlessData))

Note: Merchant need to use their private key to encrypt seamless sign

Response Header

Field NameField TypeMandatoryField Description
Content-typeStringMMedia type of the resource, i.e. application/json
X-TIMESTAMPStringMClient’s current local time in ISO-8601 format
Content-type: application/json
X-TIMESTAMP: 2024-03-19T14:30:00+07:00

Redirection Response Header

Field NameField TypeMandatoryField Description
LocationStringMGoPay PIN/OTP page URL
HTTP/1.1 302 Found
Location: https://www.integration-gws-app.gopayapi.com/app/authorize?referenceId=19352694-0ef6-4439-8ad1-b1dfb8bbb85f
HTTP/1.1 302
Location:merchantRedirectURL?responseCode=4001002&responseMessage=Invalid Mandatory Field mobileNumber

In case of a successful API request call (merchant successfully calls the Get Auth Code API), Midtrans will return Location in header with the GoPay PIN/OTP page URL. But if the call fails, Midtrans will return Location in header with the merchant's redirect URL and the error responseCode and responseMessage.

Response Query Parameter (After redirection)

Field NameField TypeMandatoryField Description
authCode
Only returned for successful response
String (256)CAuth code used to exchange with access token.
state
Only returned for successful response
String (32)CRandom string for CSRF
(Merchant can validate to check if this is the same as state sent on request).
redirectURL?authCode=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9&state=WodkkwijSD&success=true

Response Body

Field NameField TypeMandatoryField Description
responseCodeString(7)MCode to specify the response returned.
responseMessageString (150)MDebug message to provide more information.
referenceNoString (256)CDebug id to provide more information
{
   "responseCode":"2001001",
   "responseMessage":"Successful"
}
{
   "responseCode":"5001001",
   "responseMessage":"Internal Server Error",
   "referenceNo":"19352694-0ef6-4439-8ad1-b1dfb8bbb85f"
}

List of Response Code

Response CodeResponse Message
3021000
4001001Already authorized
4001002Invalid Mandatory Field mobileNumber
4011000Unauthorized. Auth token required
4011001Invalid Token (B2B)
4041012Invalid Bill/Virtual Account Not Found
This error is due to phone number is not registered on GoPay
5001001Internal Server Error
5041000Timeout