Titanium simple xhr POST of binary won't work - xmlhttprequest

I am trying to do this curl post in Titanium but I keep getting a 400 error.
I have tried passing the data as a Javascript object. I tried also changing the header.
Maybe I haven't hit the right combination of things.
Please help.
curl 'https://ortc-mobilepush.realtime.co/mp/publish' --data-binary '{"applicationKey": "[INSERT_YOUR_APP_KEY]","privateKey": "[INSERT_YOUR_PRIVATE_KEY]",
"channel" : "NewArticles",
"message" : "We have new articles for you",
"payload" : "{ \"sound\" : \"default\", \"badge\" : \"2\" }" }'
var url = 'https://ortc-mobilepush.realtime.co/mp/publish';
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug(e);
//alert('error');
},
timeout : 5000 // in milliseconds
});
client.open("POST", url);
client.setRequestHeader('Content-Type', 'multipart/form-data');
// Send the request.
var text = '{"applicationKey": "[App Key]","privateKey": "[Private key]", "channel" : "GlobalChanell", "message" : "test", "payload" : "{ \"sound\" : \"default\", \"badge\" : \"32\" }" }';
client.send(text);

recently I also faced same problem in one of my client application...
so i should give solution for that..
may be there is a problem of server url...so you can try to change that url and replace it with something below...
https://exampleserver.com/mp/publish
then set Content-Type to application/json
and create json object like below....
var text = {
applicationKey : [key],
privateKey : [p_key],
etc....
}
then pass it like....
client.send(JSON.stringify(text));

Related

Maximo REST API : MXAPIMeter Create Meter Failed

I tried to create Meter using HTTP POST olscmeter and mxapimeter.
My python code is
postReq = mxURL + "/maximo/oslc/os/oslcmeter"
headers = {'Content-type': 'application/json', 'maxauth' : maxAuth}
body = {'METERNAME' : meterName, 'METERTYPE' : meterType, 'DESCRIPTION' : description, 'READINGTYPE' : 'ACTUAL', 'MEASUREUNITID' : ''}
print(postReq, headers, body)
r = requests.post(url = postReq, headers = headers, json = body)
print(r.status_code, r.text)
And I kept encountering the under-mentioned error.
400
{"oslc:Error":
{"oslc:statusCode":"400",
"errorattrname":"metername",
"spi:reasonCode":"BMXAA4195E",
"errorobjpath":"meter",
"correlationid":null,
"oslc:message":"BMXAA4195E - A value is required for the Meter field on the METER object.",
"oslc:extendedError":{"oslc:moreInfo":{"rdf:resource":"http:\/\/mx7vm\/maximo\/oslc\/error\/messages\/BMXAA4195E"}
}
}
}
Any advice on what I have missed?
Thank you.
BMXAA4195E is just a generic error that means a required field is missing.
I have never generated MBOs this way, but I think the issue is that JSON keys are case sensitive. In all the examples I've seen online, the attributes in the body are always lowercase. This also makes sense with the error message.
Try using all lowercase keys in your body.

Bittrex API Invalid Signature Response With Python

I am trying to view my open orders through the Bittrex API but all I get is an INVALID_SIGNATURE response.
I'm using Python 3.6. Here is my code:
import time
import hmac
import hashlib
import requests
apikey = '12345'
apisecret = '56789'
nonce = str(time.time())
url = 'https://bittrex.com/api/v1.1/market/getopenorders?&apikey=' + apikey + '&nonce=' + nonce
signature = hmac.new(apisecret.encode(), url.encode(), hashlib.sha512).hexdigest()
hdrs = {'apisign' : signature}
r = requests.get(url, headers = hdrs)
print(r.json())
I'm expecting a response like:
{
"success" : true,
"message" : "",
"result" : [{
"Uuid" : null,
"OrderUuid" : "09aa5bb6-8232-41aa-9b78-a5a1093e0211",
"Exchange" : "BTC-LTC",
"OrderType" : "LIMIT_SELL",
"Quantity" : 5.00000000,
…
}
]
}
But instead I get:
{'success': False, 'message': 'INVALID_SIGNATURE', 'result': None}
I know my keys are correct, and using purposely incorrect keys changes the INVALID_SIGNATURE response to
APIKEY_INVALID. I've tried to pull other information such as "getbalance", "getorderhistory", etc., but they all give the same result.
I've found many variations of the code above, but each one I try ends with the same result. I'm sure I'm just missing something simple but after a week of searching, I still don't know why it isn't working.
Any insight is appreciated.
Thanks.

POSTMAN: Extracting Values from body

I'm trying to recreate a scenario with the postman and there is a _csrf value in the previous GET request response body to be passed with the next POST request.
I Can't find a way to extract the value from POSTMAN.
NOTE: What I want is something similar to Regular Expression Extractor in Jmeter.If you have any Idea about extracting a value form the response body and setting it to a variable. Please let me know.
Cheers,
Muditha
This might help you https://media.readthedocs.org/pdf/postman-quick-reference-guide/latest/postman-quick-reference-guide.pdf
They use Cheerio
2.2.5 How to parse a HTML response to extract a specific value?
Presumed you want to get the _csrf hidden field value for assertions or later use from the response below:
To parse and retrive the value, we will use the cherrio JavaScript library:
responseHTML = cheerio(pm.response.text());
console.log(responseHTML.find('[name="_csrf"]').val());
Cheerio is designed for non-browser use and implements a subset of the jQuery functionality. Read more about it at
https://github.com/cheeriojs/cheerio
responseHTML = cheerio(pm.response.text());
var po= responseHTML.find('[name="_csrf"]').val();
console.log(po);
pm.environment.set("token", po);
/* You need to set the environment in Postman and capture the CSRF token in variable "here po" using a get request. Next in post request the environment variable token can be used */
Just made this JS in post man to parse Without a REGEx. Hope it will help people in the futur
Text to parse : Json : Extract data-id :
{
"code": "OK",
"response": {
"append": {
"html": {
"< .folders": "<a class=\"folder\" href=\"/foobarfoo\" data-id=\"ToExtract\"><div><i class=\"far fa-fw fa-folder\"></i></div><div class=\"folder-name\">blabla</div><div><div class=\"badge\">0</div></div></a>"
}
}
}
}
console.log(responseBody.response);
var jsonData = JSON.parse(responseBody);
var iStart = responseBody.indexOf("response\":")+10;
var scenarioId = responseBody.substr(iStart,10);
var iEnd = scenarioId.indexOf("}");
var scenarioId = scenarioId.substr(0,iEnd);
console.log("scenarioId:" + scenarioId + "iStart: "+ iStart + " scenarioId : " + scenarioId);
pm.environment.set("scenario", scenarioId);

Payload data manipulation

My payload looks something like this. I am not posting the entire request.
{
"Package": {
"#UniqueID": "Some383",
"Content": {
"Application": {
"#UniqueID": "SUB1536201342468",
"PersonApplicant": [
{
"#ApplicantType": "Whateever",
"#Citizenship": "IND",
I am able to set values to the payload
* set request $.Package.Content.Application.#UniqueID = someID
But, I am unable to get a value from the request for a second service call. Below is the code I use.
* set type= request $.Package.Content.Application.PersonApplicant.#ApplicantType
I get the below error, Please advice.
jdk.nashorn.internal.runtime.ParserException: <eval>:1:13 Expected ; but found $
lixiInitiate $.Package.Content.Application.PersonApplicant.#ApplicantType
Please read the docs and examples carefully: https://github.com/intuit/karate#karate-expressions
* set type = request.Package.Content.Application.PersonApplicant.#ApplicantType

Unable to add users to existing chat in Quickblox JS

I have added a feature to QuickBlox chat sample for JS , which allows to add a new user to existing chat
function addUsers(){
var curDlgId = currentDialog._id ;
var curDlgName = currentDialog.name;
$('.users_form.active').each(function(index) {
users_ids[index] = $(this).attr('id');
});
QB.chat.dialog.update(curDlgId,{ push_all : {users_ids}}, onAddUsersCompleted);
}
function onAddUsersCompleted(error,b,c){
}
but I am getting an error on onAddUsersCompleted callback :
error = Object {code: 403, status: "error", message: "Forbidden", detail: "{"errors":["You don't have appropriate permissions to perform this operation"]}"}
Whats wrong ?
Ostap, please try to change
QB.chat.dialog.update(curDlgId,{ push_all : {users_ids}}, onAddUsersCompleted);
to
QB.chat.dialog.update(curDlgId,{ push_all : users_ids}, onAddUsersCompleted);