1. Guides
PKFARE Flight Buyer API
  • Guides
    • Quick Start
    • PKFARE Buyer API Integration Process and UAT Guide
    • Tricks for Playing with PKFARE API
    • Book air tickets with ancillaries
    • Raise refund requests
    • Raise change requests
    • Receive flight rescheduled notification
    • Add Paid Bags after the Booking
    • Branded Fare Integration Guide
    • Signature V2
  • API Reference
    • Air ticket booking APIs
      • TicketIssuanceNotify_V3
      • Shopping V10
      • PrecisePricing V12
      • Penalty V4
      • PreciseBooking V8
      • CancelOrder
      • OrderPricing V6
      • Ticketing
      • OrderDetail V14
      • RequestTicketing
      • ModifyOrderStatus
      • WalletBalance
    • Ancillary booking APIs
      • AncillaryStatusPush
      • AncillaryPricing V7
      • AncillaryBooking
      • CancelAncillaryOrder
      • AncillaryTicketing
      • AncillaryOrderDetail
    • Flight schedule change APIs
      • ScheduleChangeNotify
      • GetScheduleChangeReply
      • GetScheduleChangeList
      • AcknowledgeScheduleChange
      • AcceptScheduleChange
    • Refund APIs
      • RefundResultNotify
      • ReimbursedResultNotify
      • Refund Pricing
      • CheckRefundPricing
      • RefundRequest
      • CheckRefund
      • CheckReimbursed
      • DownloadAttachmentFile API
      • UploadAttachmentFile API
    • Change APIs
      • ChangeResultPush
      • Change Reshop
      • Change Request
      • Change Passenger Info
      • Change Reprice
      • ChangeRepricePush
    • Void APIs
      • ReimbursedResultPush
      • VoidRequest
    • Cache APIs
      • CacheShopping
      • ValidateItinerary API
    • APIs with all versions
      • CheckInInfoPush
      • Raise change requests Copy
      • Shopping
        • Shopping
        • Shopping_V2
        • Shopping_V4
        • Shopping V7
        • Shopping V9
        • Shopping V8
      • PrecisePricing
        • PrecisePricing
        • PrecisePricing_V2
        • PrecisePricing_V6
        • PrecisePricing V9
        • PrecisePricing V10
        • PrecisePricing V11
      • Penalty
        • Penalty
        • Penalty V2
        • Penalty V3
      • PreciseBooking
        • PreciseBooking
        • PreciseBooking_V2
        • PreciseBooking_V5
        • PreciseBooking V6
        • PreciseBooking V7
      • OrderPricing
        • OrderPricing_V2
        • OrderPricing V4
        • OrderPricing V5
      • Ticketing
        • Ticketing
      • TicketNumPush
        • TicketingNumPush
        • TicketingNumPush_V2
        • TicketingNumPush_V3
        • TicketIssuanceNotify
        • TicketIssuanceNotify_V2
      • CancelOrder
        • CancelOrder
      • OrderDetail
        • OrderDetail_V2
        • OrderDetail_V3
        • OrderDetail_V4
        • OrderDetail_V5
        • Json_OrderDetail_V7
        • Json_OrderDetail_V8
        • OrderDetail V9
        • OrderDetail V13
      • AncillaryPricing
        • AncillaryPricing
        • AncillaryPricing V5
        • AncillaryPricing V6
      • AncillaryBooking
        • AncillaryBooking
      • CancelAncillaryOrder
        • CancelAncillaryOrder
      • AncillaryTicketing
        • AncillaryTicketing_V2
      • AncillaryStatusPush
        • AncillaryStatusPush
      • AncillaryOrderDetail
        • AncillaryOrderDetail
      • RequestTicketing
        • RequestTicketing
      • ScheduleChangeNotify
        • ScheduleChangeNotify
      • GetScheduleChangeList
        • GetScheduleChangeList
      • AcknowledgeScheduleChange
        • AcknowledgeScheduleChange
      • AcceptScheduleChange
        • AcceptScheduleChange
      • GetScheduleChangeReply
        • GetScheduleChangeReply
      • RefundPricing
        • RefundPricing
      • CheckRefundPricing
        • CheckRefundPricing
      • RefundRequest
        • RefundRequest
      • RefundResultNotify
        • RefundResultNotify
      • CheckRefund
        • CheckRefund
      • ReimbursedResultNotify
        • ReimbursedResultNotify
      • CheckReimbursed
        • CheckReimbursed
      • UploadAttachmentFile
        • UploadAttachmentFile
      • DownloadAttachmentFile
        • DownloadAttachmentFile
      • ChangeReshop
        • ChangeReshop
      • ChangeRequest
        • ChangeRequest
      • ChangePassengerInfo
        • ChangePassengerInfo
      • VoidRequest
        • VoidRequest
        • VoidRequest_V2
      • ReimbursedResultPush
        • ReimburseResultPush_V2
  • Development Instructions
    • Signature
    • Order Status Explanation
    • Booking errors explanation and suggestions
    • Price Breakdown Explanation
    • Airlines available from PKFARE
    • PKFARE Operation Notice
    • How to retrieve airlines'PNR and ticket numbers
    • PKFARE Buyer API solutionId Usage Guide
  • Notice
    • Release Note
  1. Guides

Signature V2

Signature V2 (HMAC-SHA256)#

PKFARE is introducing a new way to authenticate API requests. Instead of the static sign field in the request body, every request carries a set of X-PK-* HTTP headers, and the X-PK-Signature header is an HMAC-SHA256 signature computed over the request path, query, body and a timestamp.
Compared with the legacy sign = MD5(partnerId + partnerKey):
The signature changes on every request, so a captured request cannot be reused after a few minutes.
The body is part of the signature, so a request cannot be modified in transit.
Keys can be rotated without downtime, because two keys can be valid at the same time.
The request and response bodies of all APIs stay the same. Only authentication changes.
TIP
This applies to the requests you send to PKFARE. The notifications PKFARE pushes to your system (for example TicketIssuanceNotify, ScheduleChangeNotify, RefundResultNotify) are not affected.

1. Authentication modes#

Your account manager sets one of the following modes on your Partner ID:
ModeLegacy signSignature V2When to use
Legacy AuthenticationAcceptedRejected (S205)Default for existing buyers
Migration ModeAcceptedAcceptedWhile you switch your system to Signature V2. Both methods work, so you can migrate API by API
Signature AuthenticationRejected (B003)AcceptedAfter your migration is complete
Recommended migration path:
1.
Ask your account manager to enable Migration Mode and issue a key.
2.
Implement Signature V2 and test it in the Sandbox environment.
3.
Switch all your production traffic to Signature V2.
4.
Ask your account manager to switch you to Signature Authentication. From then on, requests with only the legacy sign are rejected.
A mode change takes effect within about 1 minute.

2. Get your credentials#

When your account manager creates a key for you:
1.
The account manager sends you a one-time delivery link through your agreed secure channel.
2.
PKFARE sends a 6-digit verification code to the technical contact email you provided. The email shows when the code and the link expire, in UTC. The link is valid for 24 hours.
3.
Open the link, enter the verification code, and copy the three values shown:
ValueDescriptionConfidential
partnerIdYour Partner ID. The same value as in the legacy authentication.partnerIdNo
keyIdIdentifies the key, for example k_20261113_ab12cd34No
secretA Base64 string. Decode it to bytes and use the bytes as the HMAC keyYes
CAUTION
The secret is shown only once. PKFARE cannot display it again. Store it in a secret manager or an encrypted configuration, never in source code, logs, tickets or chat messages.
The link can be used only once. It stops working after 24 hours or after 5 wrong verification codes, and a code cannot be resent. In any of these cases, or if you lose the secret, contact your account manager to issue a new key.

3. Request headers#

Add all six headers to every request:
HeaderValueFormat
X-PK-Auth-Version2Fixed value
X-PK-Partner-IdYour partnerIdAs issued, including any +, /, = characters
X-PK-Key-IdYour keyIdAs issued
X-PK-TimestampCurrent Unix time in seconds (UTC)10 digits, for example 1794560400
X-PK-Request-IdA new random value for every request16-128 characters, only A-Z, a-z, 0-9 and -
X-PK-SignatureThe signature, see section 4Base64
The timestamp must be within ±300 seconds of PKFARE server time. Keep your servers synchronized with NTP.
X-PK-Request-Id helps PKFARE find your request in the logs. Please include it when you contact support.

4. Build the signature#

4.1 String to sign#

Join these 8 lines with a line feed (\n). Do not add a line feed after the last line.
PK2-HMAC-SHA256
{canonicalPath}
{canonicalQuery}
{partnerId}
{keyId}
{timestamp}
{requestId}
{payloadHash}
partnerId, keyId, timestamp and requestId must be exactly the values you send in the headers.
Then compute:
signature = Base64( HMAC-SHA256( key = Base64Decode(secret), message = UTF-8(stringToSign) ) )

4.2 Field rules#

FieldRule
canonicalPathThe URL path, percent-decoded once (UTF-8). For example /json/shoppingV10. The path must not contain an encoded / (%2F) or \ (%5C), a double-encoded character, or . / .. segments
canonicalQueryEmpty string when the URL has no query. Otherwise: split the query on &, split each part on the first =, percent-decode the key and the value, then encode them again with RFC 3986 (see below). Sort by key, then by value, comparing character codes (not locale order). Join as key=value with &
payloadHashLower-case hex SHA-256 of the exact body bytes you send. For an empty body this is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. For multipart/form-data file uploads use the fixed text UNSIGNED-PAYLOAD
RFC 3986 encoding: keep A-Z a-z 0-9 - . _ ~ as they are, encode every other byte of the UTF-8 value as %XX with upper-case hex. A space becomes %20 (not +). In a query, + is a literal plus sign and is encoded as %2B.
Canonical query examples:
Query in the URLcanonicalQuery
(none)(empty string)
currency=CNY&language=encurrency=CNY&language=en
b=2&a=1a=1&b=2
b=2&B=1B=1&b=2 (upper case sorts first)
name=hello%20worldname=hello%20world
name=hello worldname=hello%20world
c=x+yc=x%2By
a=Z&a=helloa=Z&a=hello (same key: sort by value)
TIP
Most PKFARE APIs have no query string. The simplest approach is to send the canonical query itself as the URL query, so both sides are identical.
CAUTION
Sign the body after it is serialized, and send exactly those bytes. Do not let your HTTP client re-serialize, pretty-print, compress (Content-Encoding: gzip) or change the character encoding of the body after you sign it. The maximum body size is 10 MiB.

4.3 Test vector#

Use these values to check your implementation. The secret is a sample, not a real key.
secret     : c2FtcGxlLXNlY3JldC1mb3ItZG9jcy1vbmx5LTAwMDA=
partnerId  : TestPartner+Id/Demo0000000000=
keyId      : k_20261113_ab12cd34
timestamp  : 1794560400
requestId  : 1794560400000-a1b2c3d4e5f6
method/URL : POST https://{host}/json/shoppingV10
body       : {"search":{"adults":1,"children":0,"infants":0,"nonstop":0,"airline":"","solutions":0,"tag":"","returnTagPrice":"Y","searchAirLegs":[{"cabinClass":"","departureDate":"2026-12-28","origin":"HKG","destination":"BKK","airline":""}]}}
String to sign (the third line is empty because there is no query):
PK2-HMAC-SHA256
/json/shoppingV10

TestPartner+Id/Demo0000000000=
k_20261113_ab12cd34
1794560400
1794560400000-a1b2c3d4e5f6
e3e7a58d0803494e1d7cd8963f3c0e0142d5c760f9afe771d80ef44aee6566bf
Expected signature:
Z9EwIUu0dLRhEVwZrXBLdwUpPIo9JXdQys5uYf/PO/E=

5. Test with Apifox#

5.1 Environment variables#

In your Apifox environment, add:
VariableValue
partnerIdYour Partner ID
keyIdYour Key ID
secretYour secret. Put it in the local value only (not the shared/remote value), so it is not synced to your team
Set the environment base URL to the scheme and host only, for example https://api.pkfare.com, without a path.

5.2 Pre-request script#

Add the script below as a pre-request script. To sign every request at once, add it to the folder (or project) that contains the PKFARE APIs instead of to each request.

5.3 Send a request#

1.
Open an API, for example Shopping V10 (POST /json/shoppingV10).
2.
Choose Body > raw > JSON and paste the request body. You can remove the authentication object, it is not needed with Signature V2.
3.
Send the request. The script adds the six X-PK-* headers. Do not type them by hand: the timestamp and signature must be new for every request.
4.
Check the actual request in the Apifox console: the headers must be present, and the body must be the same text you signed.
NOTE
If you see S204 in Apifox, check that the body editor does not contain comments or trailing content that Apifox removes before sending, and that the environment base URL has no path.

6. Code samples#

The samples below build the canonical query from unencoded key/value pairs and return the query string to send, so the signed query and the sent query are identical.

Java#

Python#

7. Body formats#

Body typepayloadHashNotes
JSON (application/json)SHA-256 of the JSON bytesMost APIs
Form (application/x-www-form-urlencoded, for example param=... on legacy APIs)SHA-256 of the encoded form text exactly as sent, for example param=eyJhdXRo...Build the form text yourself and sign it. In Apifox use raw body with Content-Type: application/x-www-form-urlencoded, not the form editor
File upload (multipart/form-data), for example UploadAttachmentFileUNSIGNED-PAYLOADThe path, query and headers are still signed
Empty bodySHA-256 of empty input (see section 4.2)

8. The legacy authentication object#

With Signature V2 the authentication object in the body is optional. You can remove it.
During migration you can keep it. If you keep it, authentication.partnerId must be the same as X-PK-Partner-Id, otherwise the request is rejected with B003. The legacy sign inside it is ignored when Signature V2 headers are present.
In Signature Authentication mode, a request without Signature V2 headers is rejected with B003, even when the legacy sign is correct.

9. Key rotation#

You can have up to two valid keys at the same time:
1.
Your account manager issues a new key. You receive it through a new delivery link (section 2).
2.
The old key keeps working for a retirement period agreed with your account manager (1 hour to 7 days). If you need more time, ask your account manager to extend it before it ends.
3.
Deploy the new keyId and secret before the retirement period ends. After it, requests signed with the old key are rejected with S203.
If you believe your secret has leaked, contact your account manager immediately to revoke the key and issue a new one. A revocation takes effect within about 1 minute.

10. Error codes#

Authentication errors are returned with an HTTP error status and a JSON body:
{
  "errorCode": "S202",
  "errorMsg": "timestamp out of window",
  "serverTime": 1794560400
}
serverTime (PKFARE server time in Unix seconds) is only returned with S202.
HTTPerrorCodeMeaningWhat to check
401S201Authentication header missing or invalid, invalid query encoding, or body larger than 10 MiBAll six headers are present; header formats in section 3; X-PK-Auth-Version is 2
401S202Timestamp outside the allowed windowUse Unix seconds, not milliseconds; synchronize your clock; compare with serverTime
401S203Key not found, revoked or expiredpartnerId and keyId belong together; you use the key for the correct environment (Sandbox / Production); the key has not been retired
401S204Signature does not matchSee the checklist below
401S205Signature V2 is not enabled for your Partner IDAsk your account manager to enable Migration Mode
403S206The key is not allowed to call this APIContact your account manager
400S207Request path or query is not in canonical formThe path contains %2F, %5C, a double-encoded character or . / .. segments; or (when strict checking is enabled) the URL query is not sent in canonical form
503S001Temporary system errorRetry later. If it persists, contact support with the X-PK-Request-Id
200B003Legacy sign not accepted, or authentication.partnerId differs from X-PK-Partner-IdSection 8
S204 checklist:
The secret is Base64-decoded before it is used as the HMAC key.
The string to sign has exactly 8 lines, separated by \n (not \r\n), with no line feed at the end. The query line is empty when there is no query.
The headers you send carry the same partnerId, keyId, timestamp and requestId you signed.
The body bytes you send are the bytes you hashed (no re-serialization, no compression, UTF-8).
The path is decoded once, and the query is sorted and RFC 3986 encoded (space = %20, + = %2B, upper-case hex).
Your implementation reproduces the test vector in section 4.3.

11. Go-live checklist#

Your implementation reproduces the test vector in section 4.3.
A new timestamp, request ID and signature are generated for every request, including retries.
The URL, query and body are not changed after signing.
Server clocks are synchronized with NTP.
The secret is stored securely and never logged. Do not log the X-PK-Signature header either.
All APIs you call (shopping, pricing, booking, ticketing, order detail, ancillary, refund, change, void) pass in the Sandbox environment.
Your production traffic uses Signature V2 before you ask for Signature Authentication mode.
When you contact support, provide the environment, the request time (UTC), the X-PK-Request-Id, the keyId, the full URL, the HTTP status and the errorCode. Never send your secret.
Modified at 2026-11-26 04:03:00
Previous
Branded Fare Integration Guide
Next
TicketIssuanceNotify_V3