仅使用必填字段的简单搜索查询:
{ schema_id: 'xxxxxxxx-8b39-427a-8fb8-c764957fd9c6',
filter: { last_name: { type: 'not', value: 'Smith' } } }
张贴到https://api.truevault.com/v1/vaults/xxxxxxxx-15e3-442e-aa6f-xxxxxxxx/search
POST时,POST调用选项如下所示:
{
data: { search_option: 'xxxx base64 encoded JSON.stringify of the above xxxxxxx' },
headers: { Authorization: 'Basic xxx base64 encoded API KEY xxx' }
}
授权正在运作。结果:
{错误:失败[400] {"错误":{"代码": " SEARCH.INVALID_SEARCH_QUERY"," message":"无效 search_option。","输入":" invalid_request_error" },
"结果":"错误"," transaction_id": " 9ad83046-1906-406c-87ab-963b904857c4" }
同一搜索查询的curl命令:
curl -d "{ search_option: 'eyJzY2hlbWFfaWQiOiJlOWVmYmE0NC04YjMwLTQyN2EtOGZiOC1jNzY0OTU3ZmMwZGUiLCJmaWx0ZXIiOnsibGFzdF9uYW1lIjp7InR5cGUiOiJ3aWxkY2FyZCIsInZhbHVlIjoiRnJhbnptZWllcioifX19' }"
-X POST
-H "Content-Type: application/json"
-H "Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=="
https://api.truevault.com/v1/vaults/xxxxxxxx-15e3-442e-aa6f-4xxxxxxxxxx/search
同样的错误:
{
"error": {
"code": "SEARCH.INVALID_SEARCH_QUERY",
"message": "Invalid search_option.",
"type": "invalid_request_error"
},
"result": "error",
"transaction_id": "b5a51185-264f-4765-a1b8-6ae9e491aa39"
}
答案 0 :(得分:0)
亚历,
我不认为你的curl命令的格式与TrueVault的预期方式相同。这也可能是您的http库中的问题。我期待的卷曲命令是:
curl https://api.truevault.com/v1/vaults/xyz/search \
-XPOST \
-H "Content..."
-H "Auth..."
-d "search_option=eyJ...."
也就是说,数据有效负载是表单编码的(param1=value1¶m2=value2
)而不是JSON。
看起来搜索文档缺少示例卷曲,但您可以看到文档中列出的document create类似的卷曲。
答案 1 :(得分:0)
我遇到了我在陪审团ajax请求中遇到的同样问题。对我来说,是我用header{'Content-Type':'application/json'}
发送请求,但它必须是表单数据。
工作示例:
var api_url = 'https://api.truevault.com/v1/vaults/' + vault_id + '/search';
var data = {
'schema_id' : schema_id,
'page' : 1,
'per_page' : 50,
'filter_type' : 'and',
'full_document' : false,
"sort": [
{
"SomeField":"asc"
}
],
'filter':{
'SomeField':{
'type':'eq',
'value': somevalue
}
}
};
data = btoa( JSON.stringify( data ) );
$.ajax({
type : 'POST',
url : api_url,
dataType : 'json',
processData : false,
headers : {
'Authorization':'Basic '+ btoa( auth_key+":" ),
},
mimeType : "multipart/form-data",
data : 'search_option='+ data,
error: function( response ) {
//
},
success: function( response ) {
//
}
});