How to use "designer.mocky.io" mock APIs to handle post requests? - api

I created mock API using https://designer.mocky.io/.
And I send post request to that API like below.
{
"name" : "Kamal",
"marks" : "45"
}
Then I successfully get received the response from API like below
{
"status": "success"
}
I want to get response like below.
{
"status": "success",
"name" : "Kamal"
}

Related

Is there any way to send authornicated Post and Get API requests with Selenium?

I can share the real time scenario.
Step 1: Lunch the browser perform some functional test like navigate to some page and upload a image/video file
step 2: Send a authenticated post request.
{
"predicateParams": {
"type":"dam:Asset",
"p.offset": "0",
"p.limit": "-1"
},"dateParams": {
"group.1_daterange.lowerBound":"2021-11-19T00:10:15",
"group.1_daterange.upperBound":"2021-11-19T23:59:15"
}
}
Steps 3: Read the response and find the preview URL from the response.
{
"totalAssetsModifiedOrCreated": 1,
"totalAssetsDeleted": 0,
"deletedAssets": [],
"hits": [
{
"path": "/content/dam/global-asset-library/Products/automation/download.jpg",
"renditions": [
"/content/dam/global-asset-library/Products/automation/download.jpg/jcr:content/renditions/cq5dam.web.1280.1280.jpeg"
],
"metadata": {
//Asset metadata
},
"previewLink": "https://qa.dam.com/content/dam/global-asset-library/Products/automation/download.jpg?qtm=1637340248265"
}
],
"status": {
"code": "200",
"message": "Search results found.",
"success": true
}
}
Step 4: Send a get request using to the preview link in the above response.
{
"predicateParams": {
"type":"dam:Asset",
"p.offset": "0",
"p.limit": "-1"
},"dateParams": {
"group.1_daterange.lowerBound":"2021-11-17T00:10:15",
"group.1_daterange.upperBound":"2021-11-18T23:50:15"
}
}
Step 5: validate the previously published asset returned(ex: Image)
Response of get request
Your help is highly appreciated. Thank You.
Authorization(Basic) details can be passed through
given().auth().preemptive().basic("username", "password")
preemptive() method will send the username and password irrespective of server need authentication or not.

Spring webflux webclient handling mixed response having http status code as 206

I have a scenario where the http response from a different web service can contain mixed results. For e.g
Sample Request : POST /fetchdata
{
"empIdSet": [
{
"empId": 123,
"empId": 456
}
]
}
Sample Response:
{
"empDetailsResponse": [
{
"id": 123,
"fname": "Tom",
"lname": "Smith"
"status": "Active"
},
{
"id": 456,
"status": "NOT_FOUND"
]
}
The response looks like Mono<EmpDataResponse> and the EmpDataResponse contains List<EmpDetailsResponse>
The method looks like:
Mono<EmpDataResponse> fetchData(EmpDataRequest empDataRequest)
I have ResponseHandler which is interested in !NOT_FOUND list and the ErrorResponseHandler handles cases whose status is NOT_FOUND.
Is there a way i can process my above to handlers once i get the response back from the webclient service class?
Thanks

CREATE EDUCATIONCLASS TEAMS ERROR - Team Definition. Visibility' should be equal to 'HiddenMembership'

When I want to create a team with EducationClass template, I get an error like this. I have not been receiving such an error before. All the same. what could be the problem?
{
"error": {
"code": "BadRequest",
"message": "Failed to execute Templates backend request CreateTeamFromTemplateRequest. Request Url: https://teams.microsoft.com/fabric/emea/templates/api/team, Request Method: POST, Response Status Code: BadRequest, Response Headers: Strict-Transport-Security: max-age=2592000\r\nx-operationid: 2230c436382c754aadfda14e58e7b308\r\nx-telemetryid: 00-2230c436382c754aadfda14e58e7b308-ae2a19a55b3ea34c-00\r\nX-MSEdge-Ref: Ref A: CA7D2D550A204688B37F03E163F4E43C Ref B: LON21EDGE1213 Ref C: 2020-11-23T07:20:16Z\r\nDate: Mon, 23 Nov 2020 07:20:16 GMT\r\n, ErrorMessage : {\"errors\":[{\"message\":\"'Team Definition. Visibility' should be equal to 'HiddenMembership'.\"}],\"operationId\":\"2230c436382c754aadfda14e58e7b308\"}",
"innerError": {
"date": "2020-11-23T07:20:17",
"request-id": "c67774cf-b900-4b77-9850-26f40b82e9b4",
"client-request-id": "c67774cf-b900-4b77-9850-26f40b82e9b4"
}
}
}
POST: https://graph.microsoft.com/beta/teams
{
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('educationClass')",
"displayName": "My Class Team",
"description": "My Class Team’s Description"
}
Maybe they made a breaking change in the beta version, try using v1.0 and make the request in the following way:
{
"template#odata.bind":"https://graph.microsoft.com/v1.0/teamsTemplates('educationClass')",
"displayName":"My Sample Team",
"description":"My Sample Team’s Description",
"members":[
{
"#odata.type":"#microsoft.graph.aadUserConversationMember",
"roles":["owner"],
"user#odata.bind":"https://graph.microsoft.com/v1.0/users('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')"
}
]
}

Log data from dataPower to splunk

The question might be looking easy but I am quite struck on this.
I have a requirement whereby I have to store data regarding Timestamp,latency,serviceName etc in a variable and then log that into splunk.
However I am unable to call splunk through datapower xslt.
How can we call splunk through datapower using XSLT
Thanks
Splunk has several interfaces, but XSLT is not one of them. Lucky for you, there's already a Splunk app that can collect data from Datapower and index it. See https://splunkbase.splunk.com/app/3517/.
I would consider using the Splunk HTTP Event Collector.
You can use XSLT ou Gatewayscript, in conjunction with the Datapower urlopen function (available in both language), to make a simple http call to the collector.
I found here (Code under Apache license) that the call is as simple as a call to https://SPLUNK_SVR:8088/services/collector/event/1.0 with the following body:
{
"source": "chicken coop",
"sourcetype": "httpevent",
"index": "main",
"host": "farm.local",
"event": {
"message": {
"chickenCount": 500
"msg": "Chicken coup looks stable.",
"name": "my logger",
"put": 98884,
"temperature": "70F",
"v": 0
},
"severity": "info"
}
}
I think it would work better on the datapower by using gateway script, an example of such a call can be found here. Look for the first example. You will find similar code, in which I modified the "Data" section:
//Could be added to a library
var urlopen = require('urlopen');
var jsonData = '{
"source": "Datapower",
"sourcetype": "SOMETHING DYNAMIC",
"index": "main",
"host": "GET_THIS_FROM_DP_VARIABLES",
"event": {
"message": {
"SOMECOUNTER": 500
"msg": "SOME INTERESTING INFORMATION.",
"name": "GET_THIS_FROM_DP_VARIABLES",
"put": 3333,
"yadayada": "foo",
"bar": 0
},
"severity": "info"
}
}';
var options = {
target: 'https://SPLUNK_SVR:8088/services/collector/event/1.0',
method: 'POST',
headers: { },
contentType: 'text/plain',
timeout: 60,
sslClientProfile: 'AN_EXISTING_SSL_PROFILE_ON_DATAPOWER',
data: jsonData};
urlopen.open(options, function(error, response) {
if (error) {
// an error occurred during the request sending or response header parsing
console.error("Splunk Logging - urlopen error: "+JSON.stringify(error));
} else {
// get the response status code
var responseStatusCode = response.statusCode;
var responseReasonPhrase = response.reasonPhrase;
console.log("Splunk Logging - status code: " + responseStatusCode);
console.log("Splunk Logging - reason phrase: " + responseReasonPhrase);
// no need to read response data - This is just logging
}
});

Blogger API - Google Scripts Access Token

I found this code here but I can't figure out where to get this ?
"headers" : { "Authorization" : "Bearer YOUR_ACTIVE_TOKEN"}
I have looked and researched every where but I can't find how to get this "Active Token". Can some one please help me to get this ?
function testBlogger() {
var payload =
{
"kind": "blogger#post",
"blog": {
"id": "YOUR_BLOG_ID"
},
"title": "New post",
"content": "With content..."
};
var options =
{
"method" : "post",
"headers" : { "Authorization" : "Bearer YOUR_ACTIVE_TOKEN"},
"contentType" : "application/json",
"payload" : '{ "kind": "blogger#post", "blog": { "id": "YOUR_BLOG_ID" }, "title": "New post", "content": "With content..." }'
};
try {
var result = UrlFetchApp.fetch(
"https://www.googleapis.com/blogger/v3/blogs/YOUR_BLOG_ID/posts",
options);
Logger.log(result);
} catch (e) {
Logger.log(e);
}
}
It involves a few more steps. You need to include the OAuth2 library in your project, enable the Blogger API in the Google Developers console and also create a new a browser key to get your client ID and secret.
var options =
{
"method" : "post",
"headers" : { "Authorization" : "Bearer " + getService().getAccessToken()},
"contentType" : "application/json",
"payload" : '{ "kind": "blogger#post", "blog": { "id": "YOUR_BLOG_ID" }, "title": "New post", "content": "With content..." }'
};
See: Using Blogger API with Google Apps Script
There are multiple steps required to initially setup the code environment to access OAuth2 APIs. In summary
Add an OAuth2 client library to your script project
Enable the Blogger API in the script project's associated Google Developers Console project
Setup a OAuth service in your script project
Authenticate access to generate the tokens
My blog post details all these steps https://mashe.hawksey.info/2015/10/setting-up-oauth2-access-with-google-apps-script-blogger-api-example/