金融与汇率

Flight Create Orders API

该API用于创建航班订单。使用前建议先阅读Amadeus授权指南了解如何生成访问令牌。测试环境基于生产环境的子集。

查看官方文档 ↗

接入教程

1. 阅读Amadeus授权指南获取访问令牌
2. 准备航班搜索参数
3. 调用API创建订单
4. 处理返回的订单确认信息
5. 在测试环境验证流程

使用Python创建航班订单

python
import requests
import json

# API配置
BASE_URL = 'https://api.example.com'
ENDPOINT = '/v1/booking/flight-orders'
API_KEY = 'YOUR_API_KEY'

# 请求头
headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json'
}

# 请求体示例
payload = {
    "data": {
        "type": "flight-order",
        "flightOffers": [{
            "type": "flight-offer",
            "id": "1"
        }],
        "travelers": [{
            "id": "1",
            "dateOfBirth": "1982-01-16",
            "name": {
                "firstName": "ALEXANDER",
                "lastName": "CONRAD"
            }
        }]
    }
}

# 发送POST请求
response = requests.post(
    f'{BASE_URL}{ENDPOINT}',
    headers=headers,
    data=json.dumps(payload)
)

# 处理响应
if response.status_code == 201:
    order_data = response.json()
    print(f'订单创建成功,ID: {order_data["data"]["id"]}')
else:
    print(f'请求失败: {response.status_code}')
    print(response.text)

使用PHP创建航班订单

php
<?php

// API配置
$baseUrl = 'https://api.example.com';
$endpoint = '/v1/booking/flight-orders';
$apiKey = 'YOUR_API_KEY';

// 请求头
$headers = [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
];

// 请求体示例
$payload = [
    'data' => [
        'type' => 'flight-order',
        'flightOffers' => [
            [
                'type' => 'flight-offer',
                'id' => '1'
            ]
        ],
        'travelers' => [
            [
                'id' => '1',
                'dateOfBirth' => '1982-01-16',
                'name' => [
                    'firstName' => 'ALEXANDER',
                    'lastName' => 'CONRAD'
                ]
            ]
        ]
    ]
];

// 初始化cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// 执行请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// 处理响应
if ($httpCode == 201) {
    $result = json_decode($response, true);
    echo '订单创建成功,ID: ' . $result['data']['id'];
} else {
    echo '请求失败: ' . $httpCode;
    echo $response;
}

?>

使用JavaScript创建航班订单

javascript
const axios = require('axios'); // 或使用fetch API

// API配置
const BASE_URL = 'https://api.example.com';
const ENDPOINT = '/v1/booking/flight-orders';
const API_KEY = 'YOUR_API_KEY';

// 请求头
const headers = {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
};

// 请求体示例
const payload = {
    "data": {
        "type": "flight-order",
        "flightOffers": [{
            "type": "flight-offer",
            "id": "1"
        }],
        "travelers": [{
            "id": "1",
            "dateOfBirth": "1982-01-16",
            "name": {
                "firstName": "ALEXANDER",
                "lastName": "CONRAD"
            }
        }]
    }
};

// 发送POST请求
axios.post(`${BASE_URL}${ENDPOINT}`, payload, { headers })
    .then(response => {
        if (response.status === 201) {
            console.log(`订单创建成功,ID: ${response.data.data.id}`);
        } else {
            console.log(`请求失败: ${response.status}`);
        }
    })
    .catch(error => {
        console.error('请求错误:', error.response?.data || error.message);
    });

常见问题

如何获取API访问令牌?

使用前需要先阅读Amadeus授权指南获取访问令牌。测试环境基于生产环境的子集,请确保使用正确的环境配置。

请求失败时如何排查问题?

首先检查API密钥和访问令牌是否正确,确认请求头中的Authorization格式为'Bearer YOUR_TOKEN'。然后验证请求体格式是否符合API文档要求,特别是travelers和flightOffers字段。

测试环境和生产环境有什么区别?

测试环境基于生产环境的子集,部分功能可能受限。建议先在测试环境验证集成逻辑,再切换到生产环境。两者使用相同的API端点但需要不同的访问凭证。

相似接口推荐

AWS Import/Export

AWS Import/Export服务通过邮寄物理存储设备的方式,在AWS云和用户本地环境间高效传输海量数据。该服务利用亚马逊高速内部网络直接读写存储设备,适用于大规模数据迁移场景。

待确认
AWS Greengrass

AWS IoT Greengrass可将AWS功能无缝扩展至物理设备,使设备能够本地处理生成的数据,同时仍利用云端进行管理、分析和持久存储。该服务确保设备能够快速响应本地事件,并在间歇性连接下稳定运行。

待确认
Amazon ElastiCache

Amazon ElastiCache是一项Web服务,可简化云端分布式缓存的设置、操作和扩展。它让客户能够获得高性能内存缓存的所有优势,同时减少管理负担。

待确认
Amazon Elastic Inference

Elastic Inference是AWS提供的弹性推理服务公共API。自2023年4月15日起,AWS不再接受新客户使用该服务,并协助现有客户迁移至性价比更优的替代方案。该API用于管理云端AI推理的加速计算资源。

待确认