HTTP Header response accept: application/x-pblist - json

I have some Issue with an API. I wanna fetch data over an curl command wich is working fine. But I can't handle the return type. The default header-accept look like.
-H 'Accept: application/x-bplist'
What is this fpr a return type and how can i convert it in json.
Some other request with no Accept brings back something like this (this is no json!):
{
"data1" = ();
"data2" = {
"value1" = "a...";
};
}
The () stands for an array {}; seems to be an hash, but what for a datatype is this and how to easily convert it in json?
giving an -H "Accept: application/json" will throw an error.
If you have an Idea, thanks
regards
Mat

Related

How to get an Authorization Code from UIPath

I am trying to start a robot in my UIpath-orchestrator via Google Appscript.
I have already implemented everything into my script from this documentation:
https://dev.joget.org/community/display/KBv6/Integration+with+UiPath+Robotic+Process+Automation#IntegrationwithUiPathRoboticProcessAutomation-1.GetAccessandIDTokens
But I am actually facing a problem:
Like described in 1.2 of the documentation, I need the authorization code for generating a refresh token. Since I want to write a script to obtain this automatically, the described way with pasting the URL into the browser manually with the code challenge (which btw works fine in my case) is not the way to go for me, as you probably can imagine.
Does anybody have an idea how to achieve this? I would also be fine, if you have a working Postman- or curl-approach - it wouldn’t be a problem to transform this then by myself.
Thank you in advance.
This will be deprecated anyway... :(
Actually what I have to try now is to set up an external application, which I did. I also created an access token like this:
function getAccessToken() {
var data = {
'grant_type': 'client_credentials',
'client_id': '****',
'client_secret': '*****',
'scope': 'OR.Machines'
};
var header = {
'method': 'post',
'payload': data,
};
var response = UrlFetchApp.fetch("https://cloud.uipath.com/identity_/connect/token", header);
Logger.log(response);
var messageContent = response.getContentText();
var result = JSON.parse(messageContent);
var access_token = result['access_token'];
return access_token;
}
Now what I try to do now is to get a process Release Key with whom I can start the job then...
For testing reasons, I tried it with curl:
curl -H "accept: application/json" -H "Content-type: application/json" -H "X-UIPATH-TenantName: [tenantName]" -H "X-UIPATH-OrganizationUnitId: default" --insecure -v https://cloud.uipath.com/[organization]/[TenantName]/odata/Releases?$filter=ProcessKey" -H "Authorization: Bearer [accesstoken]"
Actually what I see in the return is a 400 Bad request...
What have I done wrong?

Google App Scripts - UrlFetchApp.Fetch unable to post

I am trying to have GAS trigger an external POST request to the Adverity Datatap management API to trigger a fetch (https://help.adverity.com/hc/en-us/articles/360009502839-Datastreams-Triggering-a-Fetch) however, the response I'm receiving indicates that a GET request is being sent instead of a POST request. Is there something specific that seems off in the code below?
function triggerFetch() {
var myURL = 'https://YOUR_STACK.datatap.adverity.com/api/datastreams/684/fetch'
var options, thisDate, headers, data;
thisDate = Utilities.formatDate(new Date(), "EST-5", "yyyy-MM-dd") + 'T00:00:00Z';
headers = {
'Authorization':'Token XXXXXXXXXXXXXXXXXXXXXXXXXX'
};
data = {
'start':thisDate
,'end':thisDate.replace('T00','T12')
}
options = {
method:'POST'
,muteHttpExceptions: true
,headers:headers
,'Content-Type':'application/json'
,payload:JSON.stringify(data)
}
var response = UrlFetchApp.fetch(myURL,options);
Logger.log(response);
}
edit: for additional context, this is the working cURL output from postman
curl --location --request POST 'https://YOUR_STACK.datatap.adverity.com/api/datastreams/684/fetch/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXXXXXXXXXXXXXXXXXXX' \
--data-raw '{
"start": "2021-02-16T00:00:00Z",
"end": "2021-02-16T12:00:00Z"
}'
You can try making options contain string with ""(double quotes) instead of ''(single quotes). It should look like this:
options = {
"method" :"POST"
,"muteHttpExceptions": true
,"headers": headers
,"contentType":"application/json"
,"payload":JSON.stringify(data)
}
I was able to figure this out and am posting an answer in case it becomes relevant for anyone else. The datatap API documentation specifies that the URL should end with a trailing "/". Without this last character, a redirect occurs and the http method is reset to GET instead of POST.

Google Apps Script - Connect to external API by using a token received at login

I'm trying to work with an external API and can't make it work after the first step.
The API is for an affiliate marketing platform, 2Performant, and supports only JSON format.
The first step is to login.
In response several headers are received that define the session.
These are: access-token | client | expiry | token-type | uid
In the next request I need to inject mandatory access-token | client | uid headers.
I managed to do the first step but get an error for my second one.
This is the code that I'm using.
function apiconnect() {
var url = "https://api.2performant.com/users/sign_in.json";
var data = {
"user": {
"email": "mail#example.com",
"password": "mypassword"
}
};
var options = {
"method" : "post",
"contentType" : "application/json",
"payload" : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url,options);
var text = response.getResponseCode();
var token = response.getHeaders()["access-token"];
var client = response.getHeaders()["client"];
var uid = response.getHeaders()["uid"];
Logger.log(text);
Logger.log(JSON.parse(response.getContentText()));
Logger.log(response.getHeaders());
Logger.log(token);
Logger.log(client);
Logger.log(uid);
var urlPrograms = "https://api.2performant.com/affiliate/programs";
var optionsPrograms = {
"contentType" : "application/json",
"headers" : {"access-token": token,
"client" : client,
"uid" : uid,
}
};
Logger.log(UrlFetchApp.fetch(urlPrograms,optionsPrograms));
}
For the first part I can see the correct responses in the logs but I'm getting an error for the second one. The error is 500 (Internal Server Error).
I've noticed that I get a 401 code ("Provided session is not valid anymore either does not exist at all") if I put a random text instead of the correct one in one of the three needed headers (uid, password or token).
By using curl in the terminal, the second step works, but I can't manage to translate this in the Apps Script.
curl -H "Content-Type: application/json" -X POST -d '{"user":{"email":"mail#example.com","password":"mypassword"}}' -i https://api.2performant.com/users/sign_in.json
curl -H "Content-Type: application/json" -H "access-token: 12345" -H "client: 123" -H "uid: mail#example.com" -i https://api.2performant.com/affiliate/programs
It's probably obvious that i'm not experienced in this so hopefully I was clear enough with my description.
If you can point me to the right direction to replicate the curl in apps script that would be amazing.
Thanks!
It seems it was as simple as just adding .json to the second URL.

Meteor iron:router prepare request.body when JSON

Currently I play around with iron:router's solution for a restful API. For this I use the .put, .get ... methods which are iron:router has implemented.
This is my example I work with:
Router.route('/api', {where:'server'})
.put(function(){
var req;
req = this.request;
console.log(req.body);
this.response.end('PUT finished.');
});
When I execute the following I will get the expected response (PUT finished):
curl -XPUT "http://localhost:4000/api " -d'{"name": "timo"}'
But the console.log(req.body) returns a strange value converted to an object.
The returned value is:
{
'{"name": "timo"}\n' : ''
}
It seems that iron:router trys to convert the body into an object but did not recognized that the given request string is a valid JSON string.
Is there smth I did wrong ? I did not find anything helpful yet to prepare iron:router that the given request body is still JSON.
Maybe its a better solution not to tell iron:router that the given request is a JSON and instead to tell iron:router that it shouldn't do anything so I can convert the JSON string by myself ?
You didn't specify the content type in your curl request. Try this instead:
curl -XPUT "http://localhost:4000/api " -d'{"name": "timo"}' -H "content-type: application/json"
With that it works for me:
I20150522-09:59:08.527(-7)? Request { name: 'timo' }
(and without it doesn't).

NoJson found on an http request on play 2.3.2

i'm writing a Play 2.3.2 application using Scala.
In my controller i had a method which get the json object from the request.
The implementation is like the following:
def firstTags = Action.async { request =>
def elaborate(n: Int): Future[Result] = {//some implementation}
//get the json Object
val jsonObject = request.body.asJson
//parse the json object
jsonObject match {
case Some(json) => json \ "number" match {
case x: JsNumber => elaborate(x.as[Int])
case _ => Future{BadRequest}
}
case None => Future{BadRequest("Need a Json")}
}
}
In my route files i had:
GET /recommendation/statistic/first #recommendationsystem.controllers.manager.StatisticsController.firstTags
When i try to call the method with the curl i get always a "Need a Json" response.
I call my server with curl like the following:
curl -H "Accept: application/json" -H "Content-Type: application/json" -d '{"number": 3}' -X GET http://localhost:9000/recommendation/statistic/first
What's wrong??
GET shouldn't have body. look at HTTP GET with request body.
POST method is not only for modify the server state, but also to process data.
From RFC 2616 - HTTP/1.1:
The POST method is used to request that the origin server accept the
entity enclosed in the request as a new subordinate of the resource
identified by the Request-URI in the Request-Line. POST is designed
to allow a uniform method to cover the following functions:
Annotation of existing resources;
Posting a message to a bulletin board, newsgroup, mailing list,
or similar group of articles;
Providing a block of data, such as the result of submitting a
form, to a data-handling process;
Extending a database through an append operation.
The actual function performed by the POST method is determined by the
server and is usually dependent on the Request-URI. [...]