Fedex Logo
Developer Portal

API Authorization

บทนำ

FedEx API รองรับวิธีการยืนยันตัวตนด้วยโทเค็น OAuth 2.0 (bearer token) เพื่อให้สิทธิ์คำขอ API สำหรับแอปพลิเคชันของคุณในการเข้าถึงทรัพยากรของ FedEx การเข้าถึง OAuth นี้ต้องทำการสร้างโทเค็นใหม่ทุก 60 นาทีและใช้การทำรายการ API แต่ละรายการในการยืนยันตัวตนและให้สิทธิ์การเข้าถึงทรัพยากรของ FedEx แก่คุณ

รายละเอียด API สำหรับการอนุมัติ

API นี้ช่วยให้คุณสามารถอนุมัติกับคำขอ API และการพิสูจน์ตัวตนของทรัพยากรของ FedEx ก็เป็นสิ่งที่จำเป็น ส่วนต่อไปนี้จะอธิบายถึงข้อกำหนดเบื้องต้นของ API:

ขณะที่ลงทะเบียนเข้าสู่พอร์ทัลของ FedEx Developer ทาง FedEx จะใช้การรวมกันระหว่าง ID ลูกค้า (รหัส API) และความลับลูกค้า (รหัสลับ) เพื่อพิสูจน์ตัวตนของคำขอ API สำหรับโครงการของคุณ แต่ละโปรเจกต์ที่อยู่ภายใต้องค์กรของคุณจะเกี่ยวข้องกับการรวมกันระหว่าง ID ลูกค้าและความลับลูกค้าที่เรียกว่าข้อมูลประจำตัว API

หมายเหตุ: ลูกค้า (ภายใน ที่สามารถใช้ร่วมกันได้ ที่มีกรรมสิทธิ์หลักและรอง และผู้ที่ผสานรวม) สามารถติดต่อตัวแทนของ FedEx เพื่อรับ API และรหัสลับได้

เพื่อให้ความปลอดภัยอีกขั้นหนึ่ง ลูกค้าของ FedEx® (ภายใน ที่สามารถใช้ร่วมกันได้ ที่มีกรรมสิทธิ์หลักและรอง และผู้ที่ผสานรวม) สามารถส่งรหัสรอง (ความลับลูกค้า) และความลับรอง (รหัสผ่านลูกค้า) เพิ่มเติมนอกจากรหัส API และรหัสลับเพื่อสร้างโทเค็น OAuth ได้ โทเค็นนี้จะใช้กับทุกๆ คำขอ API เพื่อยืนยันตัวตน

คุณสามารถสร้างรหัสลับที่คุณลืมใหม่ได้จากหน้าโครงการที่พอร์ทัล FedEx Developer

หมายเหตุ: การสร้างรหัสใหม่จะส่งผลให้รหัสในแอปพลิเคชันของคุณเปลี่ยนไป

ข้อมูลสำคัญในเอกสารฉบับนี้:

  • รหัสลูกค้าคือรหัส API
  • ความลับลูกค้าคือรหัสลับ
  • รหัสรองคือรหัสลูกค้า
  • ความลับรองคือรหัสผ่านลูกค้า

ข้อมูลประจำตัว API ทำหน้าที่ต่อไปนี้:

  • จะระบุการทำโครงการที่เรียกหา API
  • จะอนุญาตการเข้าถึง API ที่เปิดอยู่ใต้โครงการของคุณ

วิธีรับข้อมูลประจำตัว API

ข้อมูลประจำตัวจะถูกสร้างขึ้นตามอินพุตใน FedEx Developer Portal:

  • ID ลูกค้า – จะสร้างรหัส API (ID ลูกค้า) เมื่อสร้างโครงการที่ FedEx Developer Portal คุณสามารถดูรหัส API ที่เกี่ยวข้องกับโครงการได้ที่หน้า ภาพรวมโครงการ
  • ความลับลูกค้า – คุณสามารถดูรหัสลับ (ความลับลูกค้า) ได้ที่หน้ายืนยันเมื่อสร้างโครงการที่พอร์ทัล FedEx Developer แล้ว รหัสลับสามารถสร้างใหม่ที่หน้า ภาพรวมโครงการ ได้หากคุณต้องการ

หมายเหตุ: ลูกค้าของ FedEx® (ภายใน ที่สามารถใช้ร่วมกันได้ ที่มีกรรมสิทธิ์หลักและรอง และผู้ที่ผสานรวม) ต้องส่งรหัสรอง (ความลับลูกค้า) และความลับรอง (รหัสผ่านลูกค้า) เพิ่มเติมนอกจากรหัส API และรหัสลับเพื่อสร้างโทเค็น OAuth ได้ ดูที่ API การสร้างข้อมูลประจำตัวเพื่อดูวิธีการสร้างรหัสรองและความลับรอง

API สำหรับการอนุมัติทำงานอย่างไร

การให้สิทธิ์อนุญาต API

เมื่อคุณได้รับข้อมูลประตัวของ API ที่ FedEx Developer Portal แล้ว ปลายทางของ OAuth จะถูกใช้เพื่อเข้าถึงโทเค็นเพื่อให้เป็นข้อมูลประจำตัวกับการทำรายการ API ต่าง ๆ

ต่อไปนี้คืออินพุตจำเป็นที่เกี่ยวข้องกับคำขอ OAuth นี้:

  • grant_type – ประเภทลูกค้า (ค่าที่ถูกต้อง: client_credentials, csp_credentials, client_pc_credentials)
  • client_id – อ้างถึงรหัส API ของโครงการ
  • client_secret – อ้างถึงรหัสลับ API ของโครงการ

สำหรับลูกค้าภายใน ที่สามารถใช้ร่วมกันได้ ที่มีกรรมสิทธิ์หลักและรอง และผู้ที่ผสานรวมของ FedEx® ต้องส่งข้อมูลเพิ่มเติมด้านล่างนี้

  • child_id – จะส่งคืนรหัสลูกค้าผ่านคำขอ API ลงทะเบียนข้อมูลประจำตัว
  • child_secret – จะส่งคืนรหัสผ่านลูกค้าผ่านคำขอ API ลงทะเบียนข้อมูลประจำตัว

ผลลัพธ์ของคำขอควรจะเป็นตามด้านล่าง:

  • access_token – โทเค็น OAuth เข้ารหัสที่จำเป็นต้องใช้ในทรานแซคชัน API
  • token_type – ประเภทของโทเค็น ในกรณีนี้คือ การยืนยันตัวตนผู้ถือครอง
  • expires_in – เวลาที่โทเค็นจะหมดอายุในหน่วยมิลลิวินาที เวลาหมดอายุโดยปกติของโทเค็นคือหนึ่งชั่วโมง
  • Scope – ขอบเขตของการอนุญาตที่ให้กับผู้บริโภค

ตัวอย่าง

คำขอ:

POST /oauth/token HTTP/1.1
grant_type= client_credentials&client_id=your client ID&client_secret=Your secret

ตอบสนอง:

{ ″access_token″: ″eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……..″,
″token_type″: ″bearer″,
″expires_in″: 3600,
″scope″: ″CXS″
}

คำขอสำหรับลูกค้าภายใน ที่สามารถใช้ร่วมกันได้ และผู้ที่ผสานรวมของของ FedEx®:

POST /oauth/token HTTP/1.1
grant_type= csp_credentials&client_id=Client ID&client_secret= Client secret&child_key=Child key&child_secret=Child Secret

ตอบสนอง:

{ ″access_token″: ″eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……..″,
″token_type″: ″bearer″,
″expires_in″: 3600,
″scope″: ″CXS″
}

คำขอสำหรับลูกค้าที่มีกรรมสิทธิ์หลักและรองของ FedEx®:

POST /oauth/token HTTP/1.1
grant_type= client_pc_credentials&client_id=Client ID&client_secret= Client secret&child_key=Child key&child_secret=Child Secret

ตอบสนอง:

{ ″access_token″: ″eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……..″,
″token_type″: ″bearer″,
″expires_in″: 3600,
″scope″: ″CXS″
}

หมายเหตุ: โทเค็นการเข้าถึงจะหมดอายุในหนึ่งชั่วโมง ทั้งนี้ สามารถสร้างใหม่ได้โดยใช้คำขอ POST ไปยังปลายทาง oauth/โทเค็นได้

API Authorization (1.0)

API Authorization

Use this endpoint to request the OAuth token (bearer token) to authorize your application to access FedEx resources. You can pass this bearer token in your subsequent individual FedEx API endpoint requests.
Note: FedEx APIs do not support Cross-Origin Resource Sharing (CORS) mechanism.

header Parameters
content-type
required
string
Example: application/x-www-form-urlencoded

This is used to indicate the media type of the resource. The media type is a string sent along with the file indicating format of the file.
Example: application/x-www-form-urlencoded

Request Body schema: application/x-www-form-urlencoded
grant_type
required
string

Specify Type of customer requesting the Oauth token.
Valid Values: client_credentials, csp_credentials, client_pc_credentials
Note:
client_credentials - should be used for customers, Integrators, and brand new Compatible Provider customers who are yet to unboard child accounts.
csp_credentials - should be used for Integrators, and Compatible Provider customers with existing child accounts.
client_pc_credentials – should be used for Proprietary Parent Child customers.

client_id
required
string

Specify the Client ID also known as API Key received during FedEx Developer portal registration.
Example: XXXX-XXX-XXXX-XXX

client_secret
required
string

Specify the Client secret also known as Secret Key received during FedEx Developer portal registration.
Example: XXXX-XXX-XXXX-XXX

child_Key
string

Specify the Client ID also known as Customer Key. This element is used as a login credential for an Integrator customer, Compatible customer or a Proprietary Parent Child customer to access the application on behalf of their customer.
Example: XXXX-XXX-XXXX-XXX
Note: This element should be used by Integrator, Compatible and Proprietary Parent Child customers.

child_secret
string

Specify the Client secret also known as Customer Secret. This element is used as a login credential for an Integrator customer, Compatible customer or a Proprietary Parent Child customer to access the application on behalf of their customer.
Example: XXXX-XXX-XXXX-XXX
Note: This element should be used by Integrator, Compatible and Proprietary Parent Child customers.

Responses

200

Success

401

Unauthorized

500

Failure

503

Service Unavailable

post /oauth/token

Sandbox Server

https://apis-sandbox.fedex.com/oauth/token

Production Server

https://apis.fedex.com/oauth/token

Request samples

Content type
application/x-www-form-urlencoded
Example
Copy
grant_type=client_credentials&client_id=Your_client_ID&client_secret=Your_secret

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX……",
  • "token_type": "bearer",
  • "expires_in": 3600,
  • "scope": "CXS"
}
CLOSE

Response

Copy