i would like to replicate all design docs and some docs that contain field clientId from orginal (A) to replication (B).
i have tried 2 ways but bothe have the same problem:
it updates my design docs continuously but not the normal docs with clientId. they only replicate one time on creation of replication.
1. try
curl -H 'Content-Type: application/json' \
-X POST http://admin:*******#mycare.owitec.lan:5984/_replicator \
-d '{
"continuous" : true,
"create_target" : true,
"source" : {
"url": "http://mycare.owitec.lan:5984/mycare_10001",
"headers": {
"Authorization": "Basic YWRtaW46QXNkZmdoKjU9"
}
},
"target" : {
"url": "http://mycare.owitec.lan:5984/mycare_rep_10001",
"headers": {
"Authorization": "Basic YWRtaW46QXNkZmdoKjU9"
}
},
"filter": "article/clientDataRep"
}'
function(doc, req) {
var v = doc._id.substr(0, 6);
if (v === '_desig' || v === '10001:') {
return true;
}
return false;
}
2. try
curl -H 'Content-Type: application/json' \
-X POST http://admin:********#mycare.owitec.lan:5984/_replicator \
-d '{
"continuous" : true,
"create_target" : true,
"source" : {
"url": "http://mycare.owitec.lan:5984/mycare_10001",
"headers": {
"Authorization": "Basic YWRtaW46QXNkZmdoKjU9"
}
},
"target" : {
"url": "http://mycare.owitec.lan:5984/mycare2_rep_10001",
"headers": {
"Authorization": "Basic YWRtaW46QXNkZmdoKjU9"
}
},
"selector": { "clientId": {"$exists": false} }
}'
i also checked both dbs for conflicts and there are none in both. what am i doing wrong? in other dbs where i have both-way-replication (from/to) i have no problems!
it was the validate_doc_update function of a design document that checked 2 things:
if it is a update then you have to be the author or have a certain rule
according to doc.type object was only allowed certain fields and i had old data that didnt conform
the replication was always running i just didnt notice (think about) that the validate_doc_update was filtering it
Related
I have a test helper function createUser that makes an HTTP request to the backend API to create a user. The backend API calls a method on Auth0 client to create a user. The responses I have are set for Auth0 client URL path /api/v2/users.
I am testing a service that has two types of users - an owner of the account and the invitee user. I am calling a helper twice before all the tests:
const owner = await createUser('owner#email.com');
const invitee = await createUser('invitee#email.com');
And I expect owner to have owner#email.com as an email and an invitee#email.com email for invitee .
In order to return two different responses I used Wiremock scenarios. And currently I have the responses like this:
User #1
{
"scenarioName": "user-scenario",
"requiredScenarioState": "Started",
"newScenarioState": "owner-user",
"request": {
"method": "POST",
"urlPattern": "/api/v2/users"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"email": "owner#email.com"
}
}
}
User #2
{
"scenarioName": "user-scenario",
"requiredScenarioState": "owner-user",
"request": {
"method": "POST",
"urlPattern": "/api/v2/users"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"email": "invitee#email.com"
}
}
}
When I run the tests Wiremock returns the second response for both createUser calls. The second response was created after the first and Wiremock prioritizes the most recently created response. I decided to set the priority: 1 on the first response to force Wiremock to return it and therefore change the scenario state. That worked only on the first test run but not for the subsequent ones.
Sometimes if I delete the Wiremock Docker image and start the container from scratch it returns the responses as expected but then continues returning the second response for both calls.
What am I doing wrong and if it's not how I set up the scenarios what could be the possible reasons for such inconsistency?
Multiple ways to skin this cat - third (response templating) is probably best.
Understanding Scenarios
The first request moves the scenario into state owner-user, and after that all requests will return user #2 for the lifetime of the WireMock instance - in your case, the docker container - unless it is reset.
You can reset it as so: PUT /__admin/scenarios/user-scenario/Started.
The state of a scenario is held in memory, so restarting the container should also reset the state to Started.
See WireMock | Stateful Behaviour | Resetting a single scenario
Using better matching to avoid scenarios
You may not need to use scenarios at all. You can use the request body of the POST to decide which stub to call, based on the email address you are sending.
Assuming your request payload looks like this:
{
"email": "owner#email.com"
}
You can match on the request body as so:
User #1
{
"request": {
"method": "POST",
"urlPattern": "/api/v2/users",
"bodyPatterns": [
{
"matchesJsonPath": {
"expression": "$.email",
"equalTo": "owner#email.com",
}
}
]
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"email": "owner#email.com"
}
}
}
User #2
{
"request": {
"method": "POST",
"urlPattern": "/api/v2/users",
"bodyPatterns": [
{
"matchesJsonPath": {
"expression": "$.email",
"equalTo": "invitee#email.com",
}
}
]
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"email": "invitee#email.com"
}
}
}
See WireMock | Request Matching | JSON Path for details.
Using response templating to reduce number of stubs
You can use values passed to WireMock in the request in the response using response templating as so:
{
"request": {
"method": "POST",
"urlPattern": "/api/v2/users"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"transformers": ["response-template"],
"jsonBody": {
"email": "{{jsonPath request.body '$.email'}}"
}
}
}
See WireMock | Response Templating | JSONPath helper for details.
There are also a variety of helpers for generating random data in various formats should you need each request to return some different value (e.g. a UUID) - see WireMock | Response Templating | Random value helper for details.
i'm trying to convert my curl to a python code, unfortunately without any success.
can anyone help me with this one, please?
curl -k -X "POST" "https://192.168.16.220:9000/api/views/search/messages" \
-H 'X-Requested-By: superman' \
-H 'Content-Type: application/json' \
-H 'Accept: text/csv' \
-u 'admin:admin' \
-d $'{
"streams": [
"62948e1fcd664d57cccfa29c"
],
"query_string": {
"type": "elasticsearch",
"query_string": "source"
},
"timerange": {
"type": "relative",
"range": 30
}
}'
This should work, also I suggest using this handy site in the future
import requests
headers = {
'X-Requested-By': 'superman',
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
'Accept': 'text/csv',
}
json_data = {
'streams': [
'62948e1fcd664d57cccfa29c',
],
'query_string': {
'type': 'elasticsearch',
'query_string': 'source',
},
'timerange': {
'type': 'relative',
'range': 30,
},
}
response = requests.post('https://192.168.16.220:9000/api/views/search/messages', headers=headers, json=json_data, verify=False, auth=('admin', 'admin'))
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{\n "streams": [\n "62948e1fcd664d57cccfa29c"\n ],\n "query_string": {\n "type": "elasticsearch",\n "query_string": "source"\n },\n "timerange": {\n "type": "relative",\n "range": 30\n }\n}'
#response = requests.post('https://192.168.16.220:9000/api/views/search/messages', headers=headers, data=data, verify=False, auth=('admin', 'admin'))
get the data from the api like this for json data
json_data = response.json()
or get the data from the api like this for text data
json_data = response.text
My objective is to post a message on personalChat in msteamsbot using restapi endpoint.
auth token is generated using below logic (reference doc)
let url = "https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token";
const data = {
'grant_type': 'client_credentials',
'client_id' : '...',
'client_secret' : '...',
'scope' : 'https://api.botframework.com/.default'
};
const options = {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(data),
url,
};
axios(options);
the token generated using above logic is passed to below api (reference doc). This api is supposed to post a message on the recipient's chat. but this doesn't happen.
curl --location --request POST 'https://smba.trafficmanager.net/apis/v3/conversations/a:1NYEIhjRpL_RgDBDaA7lJyO6kl8rbpWQLyKkayQnZ_mKOZhnKAoeuiWEekt8vpjeoIcB3R394k6-zeC52sk60Q8ErZO5PIokS8ytjD-QK-CIJjIRaGg94KzTMz2d3XXjs/activities' \
--header 'Authorization: Bearer authToken' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "message",
"recipient": {
"id":"29:1dePA4jI3vyrUt-38_--KJxVeAg_v-XQVCBHcSxp4kgu7ZshPPSbsbSOZ7m-GAKK0IARbqyxg_bit-IAt0J9d_w"
},
"from": {
"id": "28:f4016730-f1ef-4fcd-9169-4159a2295591",
"name": "Toolkit Bot - vTAPBotdemo"
},
"channelData": {
"notification": {
"alert": "true"
}
},
"text": "Hello "
}'
Below is the error message i receive when triggering the above api.
Please let me know how to resolve this issue
The endpoint i used to postMessage on personal chat is incorrect and it was present in the docs as well.
Below is the correct endpoint. This endpoint can be seen by logging the http payload request body of /api/messages api
curl --location --request POST 'https://smba.trafficmanager.net/amer/v3/conversations/{conversationid}/activities/{activityid}' \
--header 'Authorization: Bearer authToken' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "message",
"recipient": {
"id":"29:1dePA4jI3vyrUt-38_--VeAgKJx_v-CBHXQVcSxp4kgu7ZshPPSbsbSOZ7m-GAKK0IARbqyxg_bit-IAt0J9d_w"
},
"from": {
"id": "28:f4016730-f1ef-4fcd-9169-4159a2295591",
"name": "Toolkit Bot - vTAPBotdemo"
},
"channelData": {
"notification": {
"alert": "true"
}
},
"text": "Hello "
}'
Dead simple search query only using required fields:
{ schema_id: 'xxxxxxxx-8b39-427a-8fb8-c764957fd9c6',
filter: { last_name: { type: 'not', value: 'Smith' } } }
POSTing to https://api.truevault.com/v1/vaults/xxxxxxxx-15e3-442e-aa6f-xxxxxxxx/search
When POSTing, the POST call options look like this:
{
data: { search_option: 'xxxx base64 encoded JSON.stringify of the above xxxxxxx' },
headers: { Authorization: 'Basic xxx base64 encoded API KEY xxx' }
}
Authorization is working. Result:
{ Error: failed [400] { "error": { "code":
"SEARCH.INVALID_SEARCH_QUERY", "message": "Invalid
search_option.", "type": "invalid_request_error" },
"result": "error", "transaction_id":
"9ad83046-1906-406c-87ab-963b904857c4" }
curl command for the same search query:
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
Same error:
{
"error": {
"code": "SEARCH.INVALID_SEARCH_QUERY",
"message": "Invalid search_option.",
"type": "invalid_request_error"
},
"result": "error",
"transaction_id": "b5a51185-264f-4765-a1b8-6ae9e491aa39"
}
Alex,
I don't think your curl command is formatted the way TrueVault expects. This may also be your problem in your http library. The curl command I'd expect is:
curl https://api.truevault.com/v1/vaults/xyz/search \
-XPOST \
-H "Content..."
-H "Auth..."
-d "search_option=eyJ...."
That is, the data payload is form-encoded (param1=value1¶m2=value2) not JSON.
It looks like the docs for search were missing a sample curl, but you can see a similar curl for document create listed in the docs.
I ran into I believe the same issue in my juery ajax request. For me, it was that I was sending my request with header{'Content-Type':'application/json'}, but it needs to be form-data.
Working example:
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 ) {
//
}
});
Hi I am making post request to graph api(Beta) to create a task with assignee as follows.
var settings = {
"async": true,
"crossDomain": true,
"url": "https://graph.microsoft.com/beta/planner/tasks",
"method": "POST",
"headers": {
"content-type": "application/json",
"authorization": "Bearer token",
"cache-control": "no-cache",
"postman-token": "f6dd56ab-6fb4-f553-74aa-792945ba98b6"
},
"data": {"title": "testTask","planId": "rPWMLzwXlUOA33dPNU9-dWUAAoRf, "assignments": {"7d0544e0-2ed9-4aab-92a0-38efcaa292cd": {"orderHint": '5637' } } }
}
$.ajax(settings).done(function (response) {
console.log(response);
});
But it gives Error as follows,
{
"error": {
"code": "",
"message": "The request is invalid.",
"innerError": {
"request-id": "14a2ef00-a271-4be8-8197-71aa46379017",
"date": "2017-04-18T11:29:42"
},
"innererror": {
"message": "task : An error has occurred.\r\n"
}
}
}
Task resource link: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/plannertask
I see two issues with the request.
For open type properties, you need to include the type of the complex type value of the property, in this case "microsoft.graph.plannerAssignment".
The order hints sent in the request follow the format described here, your input isn't valid according to that format. In this case, since this is the first item, the order hint should be " !". You can use " !" for all order hints to have one generated for you, if you don't care about the order of items.
After making necessary changes, your request should look like this:
{"title": "testTask","planId": "rPWMLzwXlUOA33dPNU9-dWUAAoRf, "assignments": {"7d0544e0-2ed9-4aab-92a0-38efcaa292cd": { "#odata.type": "microsoft.graph.plannerAssignment", "orderHint": " !"} } }