Set Headers For Response From Webhook.Site - webhooks

I'm setting up a Custom Action on webhook.site and I have a very simple script -
if (!string_contains(var('$subscriptions$'),"active")) {
respond('{"message":"Please subscribe at website.com to use this service", "url":"website.com"}', 400);
stop()
}
I need to set the headers for the response, which their docs say should be structured like respond(string content, int status, array headers). Further down the page, they mention
headers should be an array of strings e.g. ["X-Example: Value", "X-Foo: Bar"]
but I'm not sure whether that applies to the respond() function that I'm using. When I try to set the header like this -
respond('{"message":"Please subscribe at website.com to use this service", "url":"website.com"}', 400, '["Content-Type: application/json")';
I get an error -
Wrong type of argument passed to function # line 2, position 12
and none of the other formats that I've tried have worked either. I'd appreciate any pointers!
Context - I'm using a WebhookScript action here because I need to include the logic in the if() statement. I don't want to use their Modify Response action.

Related

Sharepoint Query returns no results for with >5000 items

When I go to a specific folder in Sharepoint, I hit an error that I have exceeded the view threshold of 5000 items. I created a new view to only show items when the ID < 5000, I am able to see the folder contents now.
However, how do I apply a specific view/filter when using Python?
Using Python's request module, I have:
requestUrl = sharePointUrl + "/{0}/_api/web/GetFolderByServerRelativeUrl('/{0}/{1}')/Files".format(site, folder)
headers={'Content-Type': 'application/json; odata=verbose', 'accept': 'application/json;odata=verbose'}
requests.get(requestUrl , headers=headers).json()
which returns {'d': {'results': []}}
If I modify the requestUrl to include ?$top=1000 or ?$filter=Id lt 1000, I still have an empty result (no throttled error, just empty result)
How do I apply the filters correctly or use a specific view when running the request query?
(I used a different folder name and I get an error 'Field or property "Id" does not exist.' so clearly something is wrong with my query too but I am not sure why the other folder returns empty result and not an error)
just having a first glance on it and looking at this line
requestUrl = sharePointUrl + "/{0}/_api/web/GetFolderByServerRelativeUrl('/{0}/{1}')/Files".format(site, folder)
it will seem like the URL you want to create might be wrong. I think you should not add site to the GetFolderByServerRelativeUrl as you already will be running this in the context of the site. So for example if your site is sites/someSite and folder is shared documents you will have
sites/someSite/_api/web/GetFolderByServerRelativeUrl('/sites/someSite/shared documents')/Files
but I think you should have something like
sites/someSite/_api/web/GetFolderByServerRelativeUrl('shared documents')/Files
could you give it a double check?

Why do I fail to submit data to textarea with python requests.post()

I want to use the requests.post tool to automatically query domain name attribution on this websitea website,But the return value is always empty, I guess it is because the post method failed to transfer the data to the textarea
url = 'http://icp.chinaz.com/searchs'
data = {
'hosts':'qq.com',
'btn_search':'%E6%9F%A5%E8%AF%A2', '__RequestVerificationToken=':'CfDJ8KmGV0zny1FLtrcRZkGCczG2owvCRigVmimqp33mw5t861kI7zU2VfQBri65hIwu_4VXbmtqImMmTeZzqxE7NwwvAtwWcZSMnk6UDuzP3Ymzh9YrHPJkj_cy8vSLXvUYXrFO0HnCb0pSweHIL9pkReY',
}
requests.post(url=url,data=data,headers=headers).content.decode('utf-8')
I'd be very grateful if you could point out where I'm going wrong
I have tried to replace headers and so on.

nodejs pass parameter after parameter

I know that the title looks crazy
but here is the problem
i have a function with 2 parameter both have default value
function a(author="unknown" message="my message"){
...
}
i can access it using a("john", "hello")
but what if i need to change only the 2nd parameter?
a("","hello")
if i set the first param to "" it change the default
so i need to do?
i want is a(default,message="new message")
An alternative way to achieve this is if you can modify the function to accept an object then you can choose which parameters to pass in.
function a({ author="unknown", message="my message" } = {}){
...
}
then to call it
a({ message: "new message" }
Put simply, no, there is no way in js to get parameters by name, only by order.
You can always consult the docs for that information here.
You should call your function in the below manner.
eg.
a(undefined, "new message")
This will take default value of author and take message parameter.
This is answered properly in one of the question. Check it here

Tabulator setHeaderFilter before inital AJAX call?

I am trying to set a default headerFilter value before the table loads. I tried all the way up to tableBuild callback. Still getting 2 calls to the API, one for the regular non-filtered data then one with the default filter. The column initialValue and defaultValue params do not seem to affect filterHeaders which is why I am going down this rabbit hole.
tableBuilt: function () {
console.log("tableBuilt");
this.setHeaderFilterValue("status", "Inactive");
}
Try the initialHeaderFilter value during table creation.
initialHeaderFilter: [{field: 'fieldName', value: 'filter value'}]
http://tabulator.info/docs/4.6/filter#header
Here is a working example.
https://jsfiddle.net/nrayburn/r319zaep/40/

conditional execution of particular teststep according to result of previous request

I use SOAP UI Free.
I want to verify if previous response returns number (id) and conditionally run particular teststep.
My pseudocode below. How can I achieve this action using groovy?
How can I get response and verify if contains number and returns 200?
How can I extract this number and use it as parameter in next request
How can I compare if response is true?
response sample (200) :
523455
response sample (404) :
{
"category": "BUSINESS",
"code": "NOT_FOUND",
"description":"Account not found",
"httpStatus": 404
}
1.step GET accountId
2.step GROOVY
if(accountId is number and returns 200){
extract this number from json
run testRunner.testStep("removeAccount) for extracted number
if(response.equals("true"){
testRunner.runTestStep("createNewAccount")
}
}
1 - Use a property transfer step :
Target the id using JSONPath (should be something like "$.id")
Set "Set null on missing source" to true
Store it in a custom property of your testCase (e.g. "curId")
Additionally, if you want the Http status code, you should store it with a groovy script in another custom variable using something like this :
curHeaders = testRunner.testCase.testSteps["Get token"].testRequest.response.getResponseHeaders()
testRunner.testCase.setPropertyValue("http status", curHeaders["#status#"][0])
2 - Using a groovy script step :
Retrieve the variables above :
curId = testRunner.testCase.getPropertyValue("curId")
curHttpStatus = testRunner.testCase.getPropertyValue("http status")
Test those variables and run test step "removeAccount" if true:
if(curId && (curHttpStatus == 'HTTP/1.1 200 OK'))
{
removeActionTestStep = testRunner.testSteps["removeAccount"]
removeActionTestStep.run(null, false)
}
Note : removeAccount test step should make reference to curId custom variable (e.g. using "${#TestCase#curId}) so it runs with this id
You can add the createAccount part after the removal using jsonSlurper
removeActionResultJSON = context.expand('${removeAccount#Response}')
removeActionResultJSONSlurper = new groovy.json.JsonSlurper().parseText(removeActionResultJSON )
Then target where your response will make it equal true, then use another if - run statement like below.
Hope this helps,
Thomas

Resources