Error 500 trying to create Vertex using Rest API - orientdb

I'm trying to create a Vertex using the Rest API. I've been able to successfully use the Rest API to create a database, and to create classes (but without extending the "V" object).
However, when I try to create a Vertex using the "command" POST, I always get an error 500.
From Fiddler, here is my POST data:
POST http://dbserver:2480/command/G4JTest-8587569988225882445/sql HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: Basic cm9vdDpkYktpbmc=
Host: dbserver:2480
Content-Length: 105
Expect: 100-continue
Connection: Keep-Alive
{"command": "create class :classname extends V", "parameters": { "classname": "TestCreateVertexVertex"} }
Here's my response:
HTTP/1.1 500 Internal Server Error
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Date: Sun Oct 11 17:01:44 PDT 2015
Content-Type: application/json; charset=utf-8
Server: OrientDB Server v.2.1.2 (build UNKNOWN#r; 2015-09-09 21:41:27+0000)
Connection: Keep-Alive
Content-Length: 349
{
"errors": [{
"code": 500,
"reason": 500,
"content": "com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.{\"command\": \"create class :classname extends V\", \"parameters\": { \"classname\": \"TestCreateVertexVertex\"} }"
}
]
}
Can someone please explain what I'm doing incorrectly?

This was answered in another forum. The JSON post capability is only available in version 2.2. Since I am using 2.1.x, the error is not un-expected ...
Since 2.2 is Alpha, I'll be using the older REST interface for commands.
Or RTFM (more carefully ...)

Related

Add file to multipart form request in IntelliJ HTTP Client

I am attempting to POST an HTTP request to the Mindee API using IntelliJ IDEA's HTTP client. Specifically, I want to upload an image of a receipt. According to the documentation, the form data must have the form
{ file: your_file }
So my question is...how do I specify the field name for a file in IntelliJ's HTTP client? What is the syntax?
I've tried a few different things with similar results. I get
POST https://api.mindee.net/products/expense_receipts/v3/predict
HTTP/1.1 400 BAD REQUEST
Date: Mon, 01 Feb 2021 22:18:15 GMT
Content-Type: application/json
Content-Length: 84
Connection: keep-alive
Server: nginx/1.15.12
Access-Control-Allow-Origin: *
{
"details": {
"file": [
"This field is required."
]
},
"message": "Invalid fields in form"
}
Here are two of my attempts:
POST https://api.mindee.net/products/expense_receipts/v3/predict
Content-Type: multipart/form-data; bundary=boundary
X-Inferuser-Token: <my token>
{
file: < /path/to/image.jpg
}
POST https://api.mindee.net/products/expense_receipts/v3/predict
Content-Type: multipart/form-data; bundary=boundary
X-Inferuser-Token: <my token>
--boundary
Content-Disposition: form-data; name="file"
< /path/to/image.jpg
--boundary--
The second seemed the most promising since it took longer to return a response, but I still got the same thing.
The second attempt request should work okay, but you have a typo in there - bundary instead of boundary.

Google My Business API - Response "Method not found" 404

Just got access to the Google My Business API and have been following the instructions found here: https://developers.google.com/my-business/content/get-started
Project Info
PROJECT_ID=twocents-reviews
PROJECT_NUMBER=705754565185
I'm trying to use the OAuth 2.0 Playground to send my first Google My Business API request to https://mybusiness.googleapis.com/v3/accounts, and this is the response I get (below).
Response
GET /v3/accounts HTTP/1.1
Host: mybusiness.googleapis.com
Content-length: 0
Authorization: Bearer [**** REDACTED ****]
HTTP/1.1 404 Not Found
Content-length: 100
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-goog-trace-id: 6748d818415fd6349e9763a87acb707e
Transfer-encoding: chunked
Vary: Origin, X-Origin, Referer
Server: ESF
-content-encoding: gzip
Cache-control: private
Date: Fri, 19 Jan 2018 23:28:51 GMT
X-frame-options: SAMEORIGIN
Alt-svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
Content-type: application/json; charset=UTF-8
{
"error": {
"status": "NOT_FOUND",
"message": "Method not found.",
"code": 404
}
}
Any suggestions?
Google just hadn't finished the setup process yet. All I needed to do was wait a bit longer for the API to work for me.

REST - How to use auth token in subsequent requests

I'm using a java application the provide a REST interface for mongodb database called "RESTHeart"
When I make a normal GET request.
http -a admin:temp http://172.18.18.122:8080/_logic/roles/admin
I get an auth token Auth-Token: 10dc2eeb-9624-47f2-a542-c97e0af82b23, how can I use it subsequent requests?
Here is the full response
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Auth-Token: 10dc2eeb-9624-47f2-a542-c97e0af82b23
Auth-Token-Location: /_authtokens/admin
Auth-Token-Valid-Until: 2016-04-25T14:37:22.290Z
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 109
Content-Type: application/hal+json
Date: Mon, 25 Apr 2016 14:22:22 GMT
X-Powered-By: restheart.org
{
"_links": {
"self": {
"href": "/_logic/roles/admin"
}
},
"authenticated": true,
"roles": [
"ADMIN"
]
}
I have tried the following:
http http://172.18.18.122:8080/_logic/roles/admin Auth-Token:'10dc2eeb-9624-47f2-a542-c97e0af82b23'
Response:
HTTP/1.1 403 Forbidden
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Connection: keep-alive
Content-Length: 0
Date: Mon, 25 Apr 2016 14:30:27 GMT
X-Powered-By: restheart.org
I'm not sure what I'm doing wrong here, any ideas?
with httpie you can simply do:
http -a <username>:<Auth-Token> GET http://172.18.18.122:8080/auth/users
I found the solution for this question, all what I needed was to pass authorization header along with 'username:password' encoded in base64 format
http GET http://172.18.18.122:8080/auth/users authorization:'Basic YWRtaW46dGVtcA=='
Clients authenticate passing credentials via the standard basic authentication, a standard method for an HTTP user agent to provide a username and password when making a request.
RESTHeart is stateless: there isn't any authentication session and credentials must be sent on every request.
Of course, it means you must secure your communications with HTTPS.
There's documentation on how the authentication process works in restheart at https://softinstigate.atlassian.net/wiki/x/JgDM

REST Upload to Skydrive without Content-Length

I'm trying to upload a file to Skydrive where I don't a-priori know the Content-Length. With other storage services I can do this with chunked HTTP upload, but Skydrive always complains about Content-Length being invalid.
Here are the full headers I'm sending:
PUT /v5.0/me/skydrive/files/skydrive_test.js?overwrite=ChooseNewName HTTP/1.1
Authorization: Bearer <TOKEN_REDACTED>
host: apis.live.net
content-type: application/javascript
Connection: keep-alive
Transfer-Encoding: chunked
Here's the response I get back:
cache-control: private, no-cache, no-store, must-revalidate
transfer-encoding: chunked
content-type: application/json; charset=UTF-8
server: Live-API/16.4.1731.327 Microsoft-HTTPAPI/2.0
x-content-type-options: nosniff
x-http-live-request-id: API.c6afda25-2d9f-4248-9f49-001ccb3a9007
x-http-live-server: BAYMSG1010836
date: Wed, 15 May 2013 14:33:00 GMT
{ "error": { "code": "request_invalid_content_length",
"message": "The value for the Content-Length header isn't valid." }}
Is there any way I can do this without setting Content-Length (i.e. using chunked encoding)?
I'm using node.js to do this, but it should apply equally with any language using the REST API, hence I haven't tagged this with a particular language.
For example Dropbox offers the Chunked Upload command: https://www.dropbox.com/developers/core/docs#chunked-upload
And Google Drive, even though it says it wants Content-Length, doesn't need it for it's resumable upload API: https://developers.google.com/drive/manage-uploads#resumable
Is there an API I'm missing?
Edit: Things I've tried: Setting Content-Length: 0 results in it working, but the file is zero bytes. Setting Content-length:0 and Transfer-Encoding: chunked, results in the original error above.
Try setting a dummy content-length to see if it is acceptable. Otherwise set the file size.
If you are using node.js you can get the file size you are trying to upload and set the size to content-length in OCTETs. You can get the file size requiring the fs (filesystem) module in node.
var fs = require('fs');
fs.watchFile('some.file', function () {
fs.stat('some.file', function (err, stats) {
console.log(stats.size);
});
});
#Resource

AbsoluteURI support in Play Framework 2.1

As stated here:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
To allow for transition to absoluteURIs in all requests in future versions of HTTP, all HTTP/1.1 servers MUST accept the absoluteURI form in requests, even though HTTP/1.1 clients will only generate them in requests to proxies.
I have client which sends POST-requests to my play-2.1.1 server. He sends it this way:
POST http://172.16.1.227:9000/A8%3aF9%3a4B%3a20%3a89%3a40/1089820966/ HTTP/1.1
Content-Length: 473
Content-Type: application/json
Date: Thu, 25 Apr 2013 15:44:43 GMT
Host: 172.16.1.227:9000
User-Agent: my-client
...some data...
All requests are rejected with "Action not found" error. The very same request which I send using curl is just fine and the only difference between them is curl send it with relative URI:
POST /A8%3aF9%3a4B%3a20%3a89%3a40/1089820966/ HTTP/1.1
Accept: */*
Content-Length: 593
Content-Type: application/json
Host: 172.16.1.227:9000
User-Agent: curl/7.30.0
I created the following simple workaround in Global.scala:
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
if (request.path.startsWith("http://")) {
super.onRouteRequest(request.copy(
path = request.path.replace("http://"+request.host, "")
))
} else super.onRouteRequest(request)
}
And with this workaround all requests from my client are handled correctly.
So, is there more straightforward way to do it in Play Framework or thats the only way?
Thanks to #nraychaudhuri Play 2.2 supports absoluteURI-style request headers.
Here's the issue and pull request: https://github.com/playframework/playframework/pull/1060