Zoho Creator Deluge InvokeUrl : How to pass form parameters to third party form? - zoho

How to pass form parameters to a third-party web form with Zoho-Creator-Deluge's InvokeUrl() function?
Here is the code I have tried:
Try-1
auth_url = "https://example-form.com"
header_data = Map();
header_data.put("Content-Type","multipart/form-data");
payload = Map();
payload.put("username",app.App_Username);
payload.put("password",app.App_Password);
response = invokeurl
[
url :auth_url
type :POST
parameters:payload
headers:header_data
detailed: true
];
// debug
info response;
Try-2
auth_url = "https://example-form.com"
header_data = Map();
header_data.put("Content-Type","multipart/form-data");
payload = List();
username = {"paramName":"username","content":app.App_Username,"stringPart":"true"};
password = {"paramName":"password","content":app.App_Password,"stringPart":"true"};
payload.add(username);
payload.add(password);
response = invokeurl
[
url :auth_url
type :POST
files :payload
headers:header_data
detailed: true
];
// debug
info response;
Both Try-1 and Try-2 result in the form-page being returned in response instead of the expected logged-in page. There isn't an error message, so it seems to be ignoring the parameters in payload.
Is there a different syntax that works?
Thanks

Okay I found the issue was that I needed to use the Content-Type of x-www-form-urlencoded in my request headers. Here is the Try-1 updated with the working Content-Type:
header_data = Map();
//------------------------------------------------------------------
// This line is the fix!
//------------------------------------------------------------------
header_data.put("Content-Type","application/x-www-form-urlencoded");
payload = Map();
payload.put("username",app.App_Username);
payload.put("password",app.App_Password);
response = invokeurl
[
url :auth_url
type :POST
parameters:payload
headers:header_data
detailed: true
];
// debug
info response;

Related

Chilkat2-Python - HTTP Form Authentication problem

Trying to convert from python request to chilkat2.HttpRequest :
import requests
data = {"username": "user","password": "pass","remember": "on"}
sign_in_url = 'https://www.tradingview.com/accounts/signin/'
signin_headers = {'Referer': 'https://www.tradingview.com'}
response = requests.post(url=sign_in_url, data=data, headers=signin_headers)
token = response.json()['user']['auth_token']
P.S. Cause no right username and password - will return status_code:200
b'{"error":"Invalid username or password","code":"invalid_credentials"}'
I have this:
http = chilkat2.Http()
req = chilkat2.HttpRequest()
req.AddParam("username","user")
req.AddParam("password","pass")
req.AddParam("remember","on")
req.Path = '/accounts/signin/'
req.HttpVerb = "POST"
http.FollowRedirects = True
http.SendCookies = True
http.SaveCookies = True
http.CookieDir = "memory"
resp = http.SynchronousRequest('www.tradingview.com',443,True,req)
print(http.LastErrorText)
But response - statusCode: 403 Forbidden
What am I doing wrong?
See the tradingview.com API documentation: https://www.tradingview.com/rest-api-spec/#section/Authentication
You can see that an application/x-www-form-urlencoded POST is required.
It's easy to do with Chilkat. See this documentation showing how to send common HTTP request types: https://www.chilkatsoft.com/http_tutorial.asp
You'll want to send a request like this: https://www.chilkatsoft.com/http_post_url_encoded.asp

Bing spell check api doesn't work - error code 404

I've followed through the guide written here
https://learn.microsoft.com/en-us/azure/cognitive-services/bing-spell-check/quickstarts/python, but I'm getting a 404 error code. This is the code from the guide:
import requests
import json
api_key = myke
example_text = "Hollo, wrld" # the text to be spell-checked
endpoint = "https://api.cognitive.microsoft.com/bing/v7.0/SpellCheck"
data = {'text': example_text}
params = {
'mkt':'en-us',
'mode':'spell'
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Ocp-Apim-Subscription-Key': api_key,
}
response = requests.post(endpoint, headers=headers, params=params, data=data)
json_response = response.json()
print(json.dumps(json_response, indent=4))
But when I create a resource, the endpoint I get is either https://api.bing.microsoft.com/ or https://spellcheck3.cognitiveservices.azure.com/ depending on the guide.
How do I correctly run this code?
The code as written in the guide doesn't seem to work; here's a solution I found.
search_url = "https://api.bing.microsoft.com/v7.0/spellcheck"
search_term = "wrld helath"
params = {
'mkt':'en-us',
'mode':'spell',
'text' : search_term
}
headers = {"Ocp-Apim-Subscription-Key": subscription_key}
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()

How to get grafana alerts in ruby

I am trying to use the grafana api (doc here http://docs.grafana.org/http_api/alerting/) to get the list of all the alerts in grafana.
Here's what I tried:
uri = URI("http://example:3000")
headers = {
'Authorization'=>'Bearer test',
'Content-Type' =>'application/json',
'Accept'=>'application/json'
}
http = Net::HTTP.new(uri.host, uri.port)
request1 = Net::HTTP::Get.new("/api/dashboards/uid/uKH1CKVmk")
response1 = JSON.parse(http.request(request1).body)
This one works, it returns the json of the dashboard, but when I try :
request2 = Net::HTTP::Get.new("/api/alerts?state=ALL") or
request2 = Net::HTTP::Get.new("/api/alerts?dashboardId="+response1["id"].to_s+"")
request2['Authorization'] = "Bearer test"
request2['Content-Type'] = "application/json"
request2['Accept'] = "application/json"
I get an empty json.
Any ideas what I am doing wrong ?
Thanks,
Nicu
Found the problem, when I created the API token I selected "Viewer" permissions, I was thinking its enough to just make a get request on alerts, but apparently it is not, made a new API token with "Admin" permissions and it works.

How to parameterize Bearer token authorization in Jmeter

I have a jmeter login script where user logs in and logs out. The detailed screenshots are attached below.
Request data is as attached:
In the response date , the authorization token is generated:
And the regular expression for the same is as below:
I am passing the value as parameter in 55/users:
When I'm running the script it is failing:
Here is the response data:
Use Header Manager to pass the Token as a Header so you would have:
See for more details:
https://stackoverflow.com/a/43283700/460802
If you're looking to learn jmeter correctly, this book will help you.
A bit easier JMeter setup (login/get):
Thread Group
HTTP Request, Body Data: { "Login":"some", "Password":"credentials" }
HTTP Header Manager: content-type application/json
JSON Extractor - Names of created variables: Token; JSON Path expression: tokenName (root level in my case)
HTTP Request
HTTP Header Manager: content-type -> application/json; Authorization -> Bearer ${Token}
Response Assertion: Fields to Test = Response Code; Pattern Matching Rules = Equals, Not; Pattern to Test 401
View Results Tree to check results
Local IE Ajax version in case...
<SCRIPT>
var baseUri = 'https://localhost:port';
var tokenUri = '/something';
var getUri = '/restrictedData';
var token;
var form = { "Login":"some", "Password":"credentials" };
postRequest(baseUri + tokenUri, form, gotToken)
function gotToken(progress) {
var response = progress.srcElement;
if (response.status != 200) {
document.body.innerText = "Error:\n" + response.response;
return;
}
token = JSON.parse(response.response);
console.log(JSON.stringify(token));
var restricted = getRequest(baseUri + getUri, token.tokenName, gotRestricted);
}
function gotRestricted(progress) {
var jsonStr = progress.srcElement.response;
var jsonObj = JSON.parse(jsonStr);
document.body.innerText = JSON.stringify(token,null,2) + '\n\n' + JSON.stringify(jsonObj,null,2);
}
function getRequest(url, token, callback) {
var xhr = new XMLHttpRequest();
xhr.onloadend = callback;
xhr.open('GET', url);
xhr.setRequestHeader('contentType', 'application/json')
if (token) xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send();
return xhr;
}
function postRequest(url, body, callback) {
var xhr = new XMLHttpRequest();
xhr.onloadend = callback;
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify(body));
return xhr;
}
</SCRIPT>
Add Bearer ${token} in HTTP Header Manager available under failing HTTP Request.
If you already have the bearer token and just want to use in in header manager then,
in HTTP HEADER MANAGER tab, put these values under NAME and VALUE column respectively.
Name: Authorization
Value: Bearer "add your actual token without quotes"
Once you've extracted the token from the token API request, use this token in the HTTP Authorization Header manager for subsequent API's. Example below:
Header Name: Header Value Authorization: Bearer ${generated_token}
Where "generated_token" is a variable containing the extracted token.
I got cUrl from my API and then I imported it.
use Authorization as parameter name and value should be
Bearer ${variable_name}

View request text before sending

I'm using Net::HTTP to make a POST request:
uri = 'service.example.com'
https = Net::HTTP.new(uri)
https.use_ssl = true
path = "/service_action"
data = request_body_obj.to_json
response = https.post(path, data, {'Content-Type' => 'application/json'})
My request is timing out for some reason. To debug why, I'd like to see the text of the request body and headers of my request. Is there a way to do that?

Resources