Angular2 - Unable to fetch using a 'where' condition in query to a REST API - rest

I am working with Parse Server, and I am trying to fetch data using the REST API in my Angular2 application.
I am trying to fetch data according to a where condition, but I am not able to do so.
This is the code I am using:
constructor(http) {
var key = new URLSearchParams();
this.http = http;
this.disho = null;
key.set('where', {"estTime":"5min"});
this.http.get('https://parseapi.example.com/classes/Setto', { where : key }).subscribe(data => {
this.disho = data.json().results;
console.log(this.disho);
});
}
The above code ignore my where condition, and returns all the records.
However, the following code returns the right results when executed in terminal via cURL
curl -X GET \
-H "X-Parse-Application-Id: someKey" \
-H "X-Parse-REST-API-Key: someKey" \
-G \
--data-urlencode 'where={"estTime":"5min"}' \
https://parseapi.example.com/classes/Setto

Change { where : key } to { search : key }
Should work!

I think that there is a typo in your code. Single quotes are missing. You could try the following:
key.set('where', '{"estTime":"5min"}');

Related

marklogic api exension post binary

I wanted to create a REST service in XQuery who are able to receive zip file with documents.
I try to use the API REST extension, but the input is a document-node and is unable to receive zip file.
Is there a way to do that?
I have to receive a very big number of files, and I want to zip them by 1000 documents to limit the network time.
I use ml-gradle to create my database services
I do an other try :
XQ :
declare function he.insertMedia:put(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()?
{
let $id := map:get($params,"id")
let $uri := map:get($params,'uri')
return ( xdmp:document-insert($uri,$input),
document { <ok/> }
)
};
CURL call :
curl --location --request PUT 'http://localhost:8175/LATEST/resources/he.insertMedia?rs:id=TestMarc&rs:uri=/test/testMarc' \
--header 'Content-type: application/xslt+xml' \
--data-binary '#/D:/Travail/3-1-ELS/cep-lss-octo-exampledata/DATA/ACTUEL_ARTICLE/media/000_1wy606.jpg'
Result :
{
"errorResponse": {
"statusCode": 400,
"status": "Bad Request",
"messageCode": "XDMP-DOCUTF8SEQ",
"message": "XDMP-DOCUTF8SEQ: xdmp:get-request-body() -- Invalid UTF-8 escape sequence at line 1 -- document is not UTF-8 encoded"
}
}
ML version : 10.0-6.1
You send binary but tells the server it is XML (XSLT as XML.) Try the following in cURL:
Content-Type: application/octet-stream

How to add the column to Google Sheets using API and provide the name and type of the column in the same call?

So, what I could achieve using the Google Sheets API is being able to create a new column using the following curl based call
curl -v \
-H 'Authorization: Bearer ya29.GlxUB9K_96tyQFyQ64eaYOeImtJt32213zjosf6LW1Inv6MOqQCCodA7CycvL5EFKIpeX4dVEebS4rUl24U1J7euhMjqBZq0QEU7ZK1B64THQXNwBpDvTzoUT9hTRg' \
-H 'Content-Type: application/json' \
-d '{
"requests": [
{
"insertDimension": {
"range": {
"sheetId": 2052094881,
"dimension": "COLUMNS",
"startIndex": 0,
"endIndex": 1
}
}
}
],
}' \
https://sheets.googleapis.com/v4/spreadsheets/1mHrPXQILuprO4NdqTgrVKlGazvvzgCFqIphGdsmptD8:batchUpdate
While this call is useful, it does not completely help. This is because the reason I wanted to add a column was to give a name and type (or format) the column values. But, as per this API, this is what see as an output
Is there a way to create and add name and type to the column in a single API call?
Thanks a lot!

What is the format of the JSON for a Jenkins REST buildWithParameters to override the default parameters values

I am able to build a Jenkins job with its parameters' default values by sending a POST call to
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters
and I can override the default parameters "product", "suites" and "markers by sending to this URL:
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=ALL&suites=ALL&markers=ALL
But I saw examples were the parameters can be override by sending a JSON body with new values. I am trying to do that by sending the following json bodies. Neither of them works for me.
{
'product': 'ALL',
'suites': 'ALL',
'markers': 'ALL'
}
and
{
"parameter": [
{
"name": "product",
"value": "ALL"
},
{
"name": "suites",
"value": "ALL"
},
{
"name": "markers",
"value": "ALL"
}
]
}
What JSON to send if I want to override the values of parameters "product", "suites" & "markers"?
I'll leave the original question as is and elaborate here on the various API calls to trigger parameterized builds. These are the calls options that I used.
Additional documentation: https://wiki.jenkins.io/display/JENKINS/Remote+access+API
The job contains 3 parameters named: product, suites, markers
Send the parameters as URL query parameters to /buildWithParameters:
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=ALL&suites=ALL&markers=ALL
Send the parameters as JSON data\payload to /build:
http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build
The JSON data\payload is not sent as the call's json_body (which is what confused me), but rater in the data payload as:
json:'{
"parameter": [
{"name":"product", "value":"123"},
{"name":"suites", "value":"high"},
{"name":"markers", "value":"Hello"}
]
}'
And here are the CURL commands for each of the above calls:
curl -X POST -H "Jenkins-Crumb:2e11fc9...0ed4883a14a" http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build --user "raameeil:228366f31...f655eb82058ad12d" --form json='{"parameter": [{"name":"product", "value":"123"}, {"name":"suites", "value":"high"}, {"name":"markers", "value":"Hello"}]}'
curl -X POST \
'http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=234&suites=333&markers=555' \
-H 'authorization: Basic c2hsb21pb...ODRlNjU1ZWI4MjAyOGFkMTJk' \
-H 'cache-control: no-cache' \
-H 'jenkins-crumb: 0bed4c7...9031c735a' \
-H 'postman-token: 0fb2ef51-...-...-...-6430e9263c3b'
What to send to Python's requests
In order to send the above calls in Python you will need to pass:
headers = jenkins-crumb
auth = tuple of your (user_name, user_auth_token)
data = dictionary type { 'json' : json string of {"parameter":[....]} }
curl -v POST http://user:token#host:port/job/my-job/build --data-urlencode json='{"parameter": [{"name":"xx", "value":"xxx"}]}
or use Python request:
import requests
import json
url = " http://user:token#host:port/job/my-job/build "
pyload = {"parameter": [
{"name":"xx", "value":"xxx"},
]}
data = {'json': json.dumps(pyload)}
rep = requests.post(url, data)

Couchbase Cordova - doc_ids | Need to get uuids

I am trying to get the doc_ids in couchbase cordova to be in uuid format.
Currently, any doc that is inserted has _ids like - -AexsV4lbjOoH-AdlN1Fi0W , --mpIWIHza6CQEJEHRxPKba etc.
My setup is of such nature that the _ids need to be uuids as the cordova app will save the local DB as a part of a universal MongoDB on the server.
(So the DB on the server will have multiple local DBs stored). Hence, I need the _ids to be uuids
I did a quick research into how to create uuids in JS and found quite a few answers like -
/**
* Fast UUID generator, RFC4122 version 4 compliant.
* #author Jeff Ward (jcward.com).
* #license MIT license
* #link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
**/
var UUID = (function() {
var self = {};
var lut = []; for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); }
self.generate = function() {
var d0 = Math.random()*0xffffffff|0;
var d1 = Math.random()*0xffffffff|0;
var d2 = Math.random()*0xffffffff|0;
var d3 = Math.random()*0xffffffff|0;
return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+
lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+
lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+
lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff];
}
return self;
})();
which generates uuids like d6414228-b07c-4bd2-9aa3-d1df8b548de6
So my question is - is there a direct way inside couchbase phonegap plugin to achieve this directly?
When writing a document to Couchbase Lite, you can either let the database pick a random ID (it will be unique) or specify one.
You can send a POST request to have the database generate the document ID.
curl -H 'Content-Type: application/json' \
-vX POST 'http://localhost:5984/app' \
-d '{"name": "john"}'
{"id":"-UwALc1GlcAcG60uag1oMf1","rev":"1-10dc5637dc2ccb55e007440cca73a415","ok":true}
Or a PUT request to specify one.
curl -H 'Content-Type: application/json' \
-vX PUT 'http://localhost:5984/app/john' \
-d '{"name": "john"}'
{"id":"john","rev":"1-10dc5637dc2ccb55e007440cca73a415","ok":true}
Note that from then on you must specify the revision number of the current revision to save updates on the document.
curl -H 'Content-Type: application/json' \
-vX PUT 'http://localhost:5984/app/john?rev=1-10dc5637dc2ccb55e007440cca73a415' \
-d '{"name": "johnny"}'

Parse: Creating a New Class Programmatically

Is it possible to create a new Class programmatically (i.e. not from the dashboard) via any of the API's or the Parse CLI?
The REST API appears to have functionality to fetch, modify and delete individual Schemas (classes) but not to add them. (https://parse.com/docs/rest/guide#schemas).
Hoping for something like the following:
curl -X ADD \
-H "X-Parse-Application-Id: XXXXXX" \
-H "X-Parse-Master-Key: XXXXXXXX" \
-H "Content-Type: application/json" \
https://api.parse.com/1/schemas/City
You seem to have skipped the part which deals with adding schema in the documentation. To create a new class, according to documentation, You use following method in cURL:
curl -X POST \
-H "X-Parse-Application-Id: Your APP Id" \
-H "X-Parse-Master-Key: Your master key" \
-H "Content-Type: application/json" \
-d '
{
"className": "Your Class name goes here",
"fields": {
"Your field name here": {
"type": "Your field's data type e.g. String, Int etc. Add multiple fields if you want"
}
}
}' \
https://api.parse.com/1/schemas/[Your class name]
Or in Python:
import json,httplib
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/schemas/Game', json.dumps({
"className":"[Your class name]","fields":{"Your field name":{"type":"your field's data type"} }
}), {
"X-Parse-Application-Id": "7Lo3U5Ei75dragCphTineRMoCfwD7UJjd1apkPKX",
"X-Parse-Master-Key": "ssOXw9z1ni1unx8tW5iuaHCmhIObOn4nSW9GHj5W",
"Content-Type": "application/json"
})
result = json.loads(connection.getresponse().read())
print result