接入教程
1. 访问Adobe开发者门户获取API密钥
2. 下载Swagger AEM OpenAPI规范文件
3. 配置本地开发环境与AEM实例连接
4. 使用API密钥进行身份验证
5. 调用内容管理、工作流等端点
6. 测试API响应并集成到应用程序中
获取AEM内容列表
import requests
base_url = 'https://api.example.com'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
try:
response = requests.get(f'{base_url}/content', headers=headers)
response.raise_for_status()
content_list = response.json()
print('Content retrieved:', len(content_list))
except requests.exceptions.RequestException as e:
print('Error:', e)
创建AEM内容节点
<?php
$baseUrl = 'https://api.example.com';
$apiKey = 'YOUR_API_KEY';
$data = [
'name' => 'new_node',
'type' => 'content',
'properties' => ['title' => 'Sample Content']
];
$ch = curl_init($baseUrl . '/content');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
$result = json_decode($response, true);
echo 'Node created with ID: ' . ($result['id'] ?? 'N/A');
}
curl_close($ch);
?>
更新AEM内容属性
const baseUrl = 'https://api.example.com';
const apiKey = 'YOUR_API_KEY';
async function updateContent(contentId, newProps) {
const url = `${baseUrl}/content/${contentId}`;
const options = {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(newProps)
};
try {
const response = await fetch(url, options);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = await response.json();
console.log('Content updated:', result);
} catch (error) {
console.error('Update failed:', error);
}
}
// Example usage
updateContent('12345', { title: 'Updated Title' });
常见问题
如何获取AEM API的访问令牌?
访问令牌通常通过Adobe的OAuth认证流程获取。您需要在Adobe开发者控制台注册应用,获取客户端凭证,然后使用这些凭证通过OAuth端点交换访问令牌。具体流程请参考Adobe官方文档。
AEM API支持哪些内容格式?
AEM API主要支持JSON格式的请求和响应,用于处理结构化内容数据。对于二进制文件(如图像、文档),API通常支持多部分表单数据上传和下载。具体支持格式请查阅对应版本的OpenAPI规范。
调用AEM API时遇到认证错误怎么办?
首先检查访问令牌是否有效且未过期,确认请求头中的Authorization格式正确(Bearer TOKEN)。确保您的API密钥有足够的权限执行该操作。如果问题持续,请验证Adobe开发者控制台中的应用程序配置,或联系Adobe技术支持。
Aitishiku.com