We are trying to get the recepient activity data from Rapidmail to SFMC using the below code. It throws an error saying that >Script.Util.HttpResponse{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Not Acceptable","status":406,"detail":"Unable to resolve Accept header to a representation"}"
req.emptyContentHandling = 0;
req.retries = 2;
req.continueOnError = true;
var baseIt = Platform.Function.Base64Encode(config.username + ":" + config.password);
var auth = "Basic " + baseIt;
req.setHeader("Authorization" , auth);
req.setHeader("Accept-Language", "*");
req.method = "GET";
var res = req.send();
Write(res.content);```
Could you please let me know how to solve the issue.
Thanks,
Nikhila
Related
After seeing through this link, I tried the same in my postman.
var storageAccount = "mystorage";
var accountKey = "<<primaryKey>>";
var date = new Date();
var UTCstring = date.toUTCString();
var data = UTCstring + "\n" + "/mystorage/Health"
var encodedData = unescape(encodeURIComponent(data));
var hash = CryptoJS.HmacSHA256(encodedData, CryptoJS.enc.Base64.parse(accountKey));
var signature = hash.toString(CryptoJS.enc.Base64);
var auth = "SharedKeyLite " + storageAccount + ":" + signature;
postman.setEnvironmentVariable("auth", auth);
postman.setEnvironmentVariable("date", UTCstring);
When I make the request to ATS, to the following url,
I get the auth denied!
Can someone please guide me what's going wrong here?!
I think you need to generate a bearer token and put it to the Authorization of Postman.
If you are using C#, you can use this to get the bearer token:
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
string accesstoken = azureServiceTokenProvider.GetAccessTokenAsync("https://storage.azure.com/").Result;
string bearertoken = "Bearer " + accesstoken;
Then Copy the bearer token:
After that, it should be ok.
Just realized that the url and the data that we are encoding should exactly match the url we are querying...
After changing
var data = UTCstring + "\n" + "/mystorage/Health"
to
var data = UTCstring + "\n" + "/mystorage/Health(PartitionKey='USA',RowKey='WA')"
things started working.
Update :
It just expects the right table query. The following works fine,
var data = UTCstring + "\n" + "/mystorage/Health()"
with all filter expressions in the url being invoked from postman.
I am trying to push my JMeter result to Azure Cosmos DB through the rest API exposed from the azure portal.
To achieve so I am using JSR223 sampler (as my pre processer) to get the auth token to connect to cosmos db also using the stand script to generate the auth_token (refer:https://github.com/MicrosoftCSA/documentdb-postman-collection/issues).
But I am getting Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: ReferenceError: "request" is not defined.
Code Snippet:
var mastKey = "master_key_for_cosmos_db";
log.info("mastKey = " + mastKey);
var today = new Date();
var UTCstring = today.toUTCString();
var url = "uri_key_for_cosmos_db"
var strippedurl = url.replace(new RegExp('^https?://[^/]+/'), '/');
log.info("stripped Url = " + strippedurl);
var strippedparts = strippedurl.split("/");
var truestrippedcount = (strippedparts.length - 1);
var resourceId = "";
var resType = "";
if (truestrippedcount % 2) {
resType = strippedparts[truestrippedcount];
if (truestrippedcount > 1) {
var lastPart = strippedurl.lastIndexOf("/");
resourceId = strippedurl.substring(1, lastPart);
}
} else // its even (item request on resource)
{
resType = strippedparts[truestrippedcount - 1];
strippedurl = strippedurl.substring(1);
resourceId = strippedurl;
}
var verb = request.method.toLowerCase();
var date = UTCstring.toLowerCase();
var key = CryptoJS.enc.Base64.parse(mastKey);
var text = (verb || "").toLowerCase() + "\n" +
(resType || "").toLowerCase() + "\n" +
(resourceId || "") + "\n" +
(date || "").toLowerCase() + "\n" +
"" + "\n";
var signature = CryptoJS.HmacSHA256(text, key);
var base64Bits = CryptoJS.enc.Base64.stringify(signature);
var MasterToken = "master";
var TokenVersion = "1.0";
auth = encodeURIComponent("type=" + MasterToken + "&ver=" + TokenVersion + "&sig=" + base64Bits);
vars.put("authToken", auth);
anything I am doing wrong or missed?
This request object belongs to Postman tool, you cannot use it in your JMeter scripts as it is not defined there.
You will also need to import this CryptoJS which might not be trivial.
Moreover the recommended language for scripting in JMeter is Groovy
So instead of trying to copy and paste someone's Postman code into JMeter which will not work I would rather recommend going into one of the following directions:
Use Azure Cosmos DB Java SDK for SQL API from JSR223 Test Elements using Groovy language
Or replicate the Postman's JavaScript in Groovy like it's described in How to Handle Dynamic AWS SigV4 in JMeter for API Testing article
I have the following code sample with which I'm trying to authenticate an Azure active directory user within a Xamarin forms app
The URL (I've removed the actual client ID) works fine in a browser but fails when trying to send the http request
The error message says 'the response type must include client_id'
string URL = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?"
+ "client_id=xxxx-xxxxx-xxxxx-xxxxx-xxx"
+ "&response_type=code"
+ "&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient"
+ "&response_mode=query"
+ "&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read"
+ "&state=12345";
var webRequest = System.Net.WebRequest.Create(URL) as HttpWebRequest;
System.Console.WriteLine(URL);
if (webRequest != null)
{
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout = 20000;
webRequest.ContentType = "text/html";
//POST the data.
using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter.Write(postData);
}
}
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
ret = reader.ReadToEnd();
You put parameters in the URL, so you need to use GET method, instead of POST (like your browser does when you paste the URL in its address bar).
So, replace:
webRequest.Method = "POST";
by:
webRequest.Method = "GET";
and remove:
//POST the data.
using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter.Write(postData);
}
I am trying to call a RestLet webservice/URL from another SuiteScript. As i understand I need to use the http/https module to do so. But I am not able to find some example or steps to do so.
Planning to use this code in SS2.0-
var response = http.post({
url: 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=601&deploy=1',
body: myDataObj, // json object
headers: headerObj // json obj
});
The below code works for me.
var nameValue = "arin";
var myDataObj = {
"name" : nameValue
};
var myRequest = {};
myRequest.headers = {};
myRequest.headers["Authorization"] = 'NLAuth nlauth_account=TSTDRV158xxxx,nlauth_email=XXXX,nlauth_signature=XXXX,nlauth_role=3';
myRequest.headers["Content-Type"] = 'application/json';
myRequest.headers["Accept"] = '*/*';
myRequest.url = 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=601&deploy=1'; // RESTlet
// URL
myRequest.method = "POST";
myRequest.body = JSON.stringify(myDataObj);
// myRequest.body = myDataObj;
var myResponse = https.post(myRequest);
And reading the response data for JSON return ...
log.debug("Resonse", myResponse.body);
log.debug("Resonse", myResponse.code);
var data = myResponse.body;
var retObj = JSON.parse(data);
log.debug("Resonse Ret city - ", retObj.city);
Here's a basic example of how to do it:
var myRequest = {};
myRequest.headers = {};
myRequest.headers["Authorization"] = 'NLAuth nlauth_account=TSTDRVXXXXX, nlauth_email=xxx#xxx.com, nlauth_signature=XXXXXXX, nlauth_role=3';
myRequest.headers["contentType"] = 'application/json';
myRequest.url = 'https://XXXXXXXXX'; //RESTlet URL
myRequest.body = myDataObj;
var myResponse = https.post(myRequest);
Be careful exposing this on clientside scripts. You don't want to expose your credentials.
I am new user on stackoverflow as well as in office 365 development using node.js.
I am successfully getting User(my own office 365 account) mails,calendar events using this tutorial (https://dev.outlook.com/RestGettingStarted/Tutorial/node)
but when i am trying to Create an Event in my calender it gives me below error
"{"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}"
Please provide me suggestions on the same.
Below is the code for creating event which i copied from [https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations#CreateEvents] here
function createEvent(response, request) {
var cookieName = 'node-tutorial-token';
var cookie = request.headers.cookie;
// if (cookie && cookie.indexOf(cookieName) !== -1) {
console.log("Cookie: ", cookie);
// Found our token, extract it from the cookie value
var start = cookie.indexOf(cookieName) + cookieName.length + 1;
var end = cookie.indexOf(';', start);
end = end === -1 ? cookie.length : end;
var token = cookie.substring(start, end);
console.log("Token found in cookie: " + token);
var event = new outlook.Microsoft.OutlookServices.Event();
event.subject = 'Your Subject';
event.start = new Date("October 30, 2014 11:13:00").toISOString();
event.end = new Date("October 30, 2014 12:13:00").toISOString();
// Body
event.body = new outlook.Microsoft.OutlookServices.ItemBody();
event.body.content = 'Body Content';
event.body.contentType = outlook.Microsoft.OutlookServices.BodyType.Text;
// Location
event.location = new outlook.Microsoft.OutlookServices.Location();
event.location.displayName = 'Location';
// Attendee
var attendee1 = new outlook.Microsoft.OutlookServices.Attendee();
var emailAddress1 = new outlook.Microsoft.OutlookServices.EmailAddress();
emailAddress1.name = "abc";
emailAddress1.address = "abc#abcdt.onmicrosoft.com";
attendee1.emailAddress = emailAddress1;
event.attendees.push(attendee1);
var outlookClient = new outlook.Microsoft.OutlookServices.Client('https://outlook.office365.com/api/v1.0',
authHelper.getAccessTokenFn(token));
outlookClient.me.calendar.events.addEvent(event)
.then(function (response) {
console.log(response._Id);
}, function (error) {
console.log(error);
});
}
Make sure your app has requested for calendar.readwrite permission and you need this to create new events. In the example you followed, your app registered for only Calendar.Read permissions (see below).
You should instead go to https://dev.outlook.com/AppRegistration to register an app with Calendar.ReadWrite permission which is required to create new events.