Using Transactions with GraphDB REST API to push a file into a repository - rest

i have the following requirement:
After selecting an ontology file i need to send it into my GraphDB-Repository. I´m programming with Angular 8.
I looked at the REST API Documentation and tried my best to understand what i need to do (i have like 3 months of experience with coding in angular [and overall actually], so all these concepts are still pretty new to me).
So i figured out i could start a new transaction, get the transaction-id and use it to submit my file. I dont know if this appraoch works, but anyway i´m not able to get the transaction-id, because it appears nowhere in the server response.
Recording to the documentation it should be in the header. But there is only the following content:
"cache-control": "no-store",
"content-language": "de",
"content-type": "text/plain;charset=UTF-8"
Thanks in advance!
var config_post: AxiosRequestConfig = {
method: `POST`,
headers: {
'Content-Type': 'application/json',
'Accept': 'text/plain',
},
// responseType: 'text',
// data: formData,
url: "http://localhost:7200/repositories/testdb/transactions"
}
Axios(config_post).then(function (response) {
console.log("Got a response from GraphDB ");
console.log(response.headers);
})

As Damyan mentioned, you don't need to start a transaction to upload a file. You can do something like:
curl -X POST -H "Content-Type: application/x-trig" --data-binary '#test_data.trig' 'http://localhost:7200/repositories/test/statements'
or
curl -X POST -H "Content-Type: application/x-trig" -T test_data.trig 'http://localhost:7200/repositories/test/statements'

Related

Sends a request-body in a GET

I'm trying to get data from API
I used curl to send a request body
curl -H "Content-Type: application/json" exemple.com/api/filter -XGET -d '{"param1": "aa"}'
and it's works, I've a data result but using axios it doesn't work
axios.get("exemple.com/api/filter", {data: {"param1": "aa"}}).then(response => {
return response.data;
}).catch(err => {
alert(err);
console.log(err);
})
There are any way to have an equivalent of curl -xGET to Axios ?
Thanks!
If this is run on the browser it will not work since:
The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD.
https://xhr.spec.whatwg.org/#the-send()-method
However, if you running this on node engine it should work.
You should think about switching to axios.post to send json data to your api instead of get. If you are trying to get data then use query params axios.get(..., {params: {"param1": "aa"}}).

Postman - submit token

I'm new with Postman,(until today never used it)
I want this API request to run through Postman (pretty output)
curl -X GET http://localhost/api/myapi/subnets/ --header "token: token"
Through Postman i can easily get this token:
http://localhost/api/myapi/user/
Output:
{
"code": 200,
"success": true,
"data": {
"token": "token",
"expires": "2019-09-13 19:29:55"
},
"time": 0.013
}
But i don't know how to pass --header "token:token" part to Postman
I tried a couple of suggestion from Stack Overflow but none seems to work.
In the header section you can add the header param you want:
just write in the "key" column.
The Authorization section is an easy way to add the common "Authorization" header. All others header should be added by "Headers" section.
The request in my image is the same of your curl command.
Found it on this link: https://www.quora.com/How-can-I-convert-cURL-code-to-Postman
http://localhost/api/myapi/subnets/?Authorization= token

Upload and Name a File Using Google Drive REST API v3 and Angular 2

I'm creating a Google Drive service using the Drive REST Api v3 in Angular 2. Most of the functionality is in place: view file, download, create etc.. but I cannot find how to name a file (either when creating a file or updating).
I'm using the following docs pages: create and update. They say the file name should be part of the request body. The relevant code from my Google Drive service is bellow.
createFile(name :string, content :string) :Promise<Object> {
let headers = new Headers({
'Content-Type': 'text/markdown',
'Authorization': 'Bearer ' + this.token,
'name': name //TODO name not working!
});
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http
.post('https://www.googleapis.com/upload/drive/v3/files' + '?uploadType=multipart', content, options)
.toPromise();
}
updateFile(id :string, content :string, name :string) :Promise<Object> {
let headers = new Headers({
'Content-Type': 'text/markdown',
'Authorization': 'Bearer ' + this.token,
'id': id,
'name': name //TODO name not working!
}); //generate headers
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http
.patch('https://www.googleapis.com/upload/drive/v3/files/' + id + '?uploadType=multipart', content, options)
.toPromise();
}
To summarise files are being created and updated fine (including content) but naming and renaming a file doesn't work at all.
Thanks for any help.
Try placing name in the request body and not in the request header as described in the Files: create:
Request body
In the request body, supply a Files resource with the following properties as the metadata. For more information, see the document on media upload.
To test it, try using API Explorer to help you explore various Google APIs interactively.
Sample Request:
POST https://www.googleapis.com/drive/v3/files?key={YOUR_API_KEY}
{
"name": "My File"
}
Response:
200
{
"kind": "drive#file",
"id": "fileID",
"name": "My File"
}
There is also a related SO post that explain how to insert file to Google Drive through API.
Hope this helps.
I also faced that problem. I think there is 3 solutions:
Use multipart upload https://developers.google.com/drive/v3/web/multipart-upload with different headers for file metadata and actual file. Me myself stuck there, didn't found how to add boundaries to separate request headers in Angular 2+
Upload file in two requests. First to create empty file with metadata (response will provide id of the file) and second to actually "update" the file.
Use resumable upload. First request to "setup metadata" (will not even create empty file) and get "special link" where to send request to upload actual file. And this approach have some other features, like uploading in chunks.https://developers.google.com/drive/v3/web/resumable-upload
Here is the link to another Question with implementation of resumable upload in Angular 2 and DRIVE REST API V3
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name
I hope it might be useful.
You are trying to set the name using an http header. This is wrong. I can't begin to understand how you thought that was the way to do it, so you need to go back and reread the Drive API documentation.
In short, the name: "name" should be a JSON object passed in the body of the request, not in an http header.

How to make a correct HTTP Post request with Meteor.js to Domino Datalab's Rest API

In my server side Meteor.js method, I'm trying to correctly make a request to Domino Data Lab's (DDL) Rest API.
DDL provides a platform for makes it possible to call a data science model via a REST API. Their documentation on this API is here:
http://support.dominodatalab.com/hc/en-us/articles/204173149-API-Endpoints-Model-Deployment
But, I doubt the documentation is helpful because I think an experienced Meteor developer will see the request examples in CURL or Python and know how to get the params correctly into the JSON format that DDL is looking for.
Domino Datalab provides the instructions for 4 methods, but not for Meteor.js. I'll post the examples for Curl and Python:
Examples
CURL Request
curl -v -X POST \
https://app.dominodatalab.com/MYURL \
-H 'Content-Type: application/json' \
-H 'X-Domino-Api-Key: YOUR_API_KEY' \
-d '{"parameters": [ "FOO", "BAR", "ETC"]}'
Python Request
import requests
response =
requests.post("https://app.dominodatalab.com/MYURL",
headers = {
"X-Domino-Api-Key": "YOUR_API_KEY",
"Content-Type": "application/json"
},
json = {
"parameters": ["FOO", "BAR", "ETC"]
}
)
print(response.status_code)
print(response.headers)
print(response.json())
I've tried a few different ways (using both the dataand paramsoptions) based on the documentation for Meteor, but here is my best try:
Meteor.methods({
score_app: function(){
var test = HTTP.call("POST", "https://app.dominodatalab.com/MYURL",
{ headers: {
"Content-Type": "application/json",
"X-Domino-Api-Key": "YOUR_API_KEY"
},
// This is where the problem is. Have tried multiple syntax versions and tried using the `params`options for the HTTP call instead of `data`
data: {'params': [143]
}
},
function (error, result) {
// The syntax below should be if not an error, log the result (for testing etc, otherwise, log "http post error". I may have incorrectly switched this around, but the original version I got from an online example had it the console.log statements in the reverse order.
if (!error) {
console.log(result);
} else{
console.log("http post error");
};
});
}
});
I've been using this entry in the Meteor documentation to send the parameters as a JSON object correctly:
http://docs.meteor.com/api/http.html
The connection to Data Domino Lab (DDL) is made correctly, but it doesn't recognize the parameters correctly because the request is not sending the parameters in the JSON format that DDL wants.
result: 'You must provide a JSON object in your request body
with a parameters key containing an array of parameters.' } }
I'm on the DDL free plan, but I will email a link to this question to their tech support. This is a niche issue, but it could be important to Meteor.js developers in the future wishing to link to a data science model in DDL.
I'm one of the engineers at Domino who has worked on the API Endpoints feature recently. The error
message you're getting means that the JSON object you're sending to our server doesn't contain the
key "parameters". I'm not an expert in Meteor, but it looks like you're using "params" where you
should use "parameters" in your JSON payload.
Around line 9 can you change...
{'data': {'params': [143]}}
to
{'data': {'parameters': [143]}}
If my understanding of your code is correct, that'll work correctly.
Cheers!

POST multiple worklogs in one JIRA Rest request

I have the following data, hoping to insert two worklogs at once into the same issue using the rest url:
curl -u jogbra:jogbra -X POST -k --data #data_holiday.txt -H "Content-Type: application/json" https://jira.myworkplace/jira/rest/api/2/issue/4371/worklog
data_holiday.txt contains:
{
"comment": "Christmas Day",
"started": "2015-12-25T08:50:09.423+0000",
"timeSpent": "8h 0m"
},
{
"comment": "Labor Day",
"started": "2015-09-07T08:50:09.423+0000",
"timeSpent": "8h 0m"
}
It only gets the first holiday (with or without the comma).
End goal is to automate the population of holidays. I don't see a way of making more than one worklog with one request, so should I resort to using a loop to call curl? If I do that, do I need to create one data file for each holiday?
I see from this post that google has solved this batch request issue with a "batch" endpoint. How would I accomplish this in jira?
Sorry, but in JIRA only one worklog per on request: https://docs.atlassian.com/jira/REST/latest/#d2e795