Passing json content using telnet - json

I'm trying to pass json using telnet, here is my usecase:
mohamadm-mac:~ mohamadm$ telnet 192.168.56.5 8081
Trying 192.168.56.5...
Connected to ip-192-168-56-5.eu-west-1.compute.internal.
Escape character is '^]'.
PUT http://192.168.56.5:8081/artifactory/api/repositories/test-local HTTP/1.0
Content-Type: application/json
{"rclass" : "local"}
HTTP/1.1 500 Internal Server Error
Server: Artifactory/5.8.4
X-Artifactory-Id: 84c66c5bb11d016e:-6e6f432f:161a8395cb7:-8000
Content-Type: application/json
Date: Fri, 02 Mar 2018 16:25:40 GMT
Connection: close
{
"errors" : [ {
"status" : 500,
"message" : "No content to map to Object due to end of input"
} ]
}Connection closed by foreign host.
How can I resolve this? I need to use telnet like the following curl:
curl -XPUT http://192.168.56.5:8081/artifactory/api/repositories/test-local -H "Content-Type: application/json" -d '{"rclass" : "local"}' -uadmin:password
Thank you in advance for helping.

Related

Sending JSON file using relative path with curl

I have a JSON file called people.json:
[
{
"name": "Adam"
},
{
"name": "Eve"
}
]
I'm trying to send this data using a POST request with curl, from the project's root directory:
curl --request POST \
--header 'Content-Type: application/json' 'Accept: application/json' \
--data-binary #src/test/java/com/spring/app/people.json \
http://127.0.0.1:8080/api/v1/person -v -s
I keep getting the "Bad Request" error:
* Closing connection -1
* Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> POST /api/v1/person HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.74.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 80
>
* upload completely sent off: 80 out of 80 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Sat, 12 Dec 2020 03:56:38 GMT
< Connection: close
<
* Closing connection 0
{"timestamp":"2020-12-12T03:56:38.822+00:00","status":400,"error":"Bad Request","message":"","path":"/api/v1/person"}%
I've already had a look at this post, but still get the same error.
I've also installed homebrew curl, but even using that doesn't resolve the error.
I would appreciate any help.

Curl command for creating Github Repository is not working

I tried the following code for creating a repository. But it gives JSON parsing problem. What causes this?. I took this code from https://docs.github.com/en/rest/reference/repos tried in python code using requests.post method. But that too gave the same error Problem Parsing JSON. Is this bad request or the parsing problem is inside Github API.
curl -i -H "Authorization: token MYACCESSTOKENHERE" \
-d '{ \
"name": "simp", \
"auto_init": true, \
"private": true, \
"gitignore_template": "nanoc" \
}' \
https://api.github.com/user/repos
Output:
HTTP/1.1 400 Bad Request
Date: Sun, 09 Aug 2020 05:14:23 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 159
Server: GitHub.com
Status: 400 Bad Request
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4956
X-RateLimit-Reset: 1596950918
X-OAuth-Scopes: admin:gpg_key, admin:org, admin:org_hook, admin:repo_hook, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages
X-Accepted-OAuth-Scopes: public_repo, repo
X-GitHub-Media-Type: github.v3; format=json
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: B649:25C9:CDEF3A:117E0EE:5F2F862F
{
"message": "Problems parsing JSON",
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-for-the-authenticated-user"
}
Could you please validate your token is authorized.
Please refer Authorizing OAuth Apps
curl -H "Authorization: token OAUTH-TOKEN" <https://<your_repo_endpoint> -I
Update using JSON formatter
"-d""{ \\
\"name\": \"simp\", \\
\"auto_init\": true, \\
\"private\": true, \\
\"gitignore_template\": \"nanoc\" \\
}""\\
The problem is with the JSON format. After I removed unwanted lines and spaces from the curl command, it worked.
curl -i -H "Authorization: token 1f003ae8eab2feea72630d6f3150b921a522a868" -d '{ "name": "simp1", "private": true}' https://api.github.com/user/repos

Google Drive Doc Fill/AppScripts

I've been working with the Google Drive API in my Java application. The goal is to have a framework for our internal AppEngine project to fill out various templates in our organization's Team Drives.
I have setup a Service Account with domain-wide permissions and have gone through the "Executing Functions using the Apps Script API" documents. I can use the Java v3 library to update a sheet to get some number information, copy the template to a new file in the Team Drive. I've written a simple AppScript function to take in the Docs File Id and a JSON string representing the token/value pairs to substitute.
Everything goes great until it's time to execute the script when I get:
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Request contains an invalid argument.",
"reason" : "badRequest"
} ],
"message" : "Request contains an invalid argument.",
"status" : "INVALID_ARGUMENT"
}
Not sure how to debug or change this error, as I don't really get any additional info. I do see the request being made in the AppScript API and project console, but don't know how to get more information.
My code to execute is as follows:
List<Object> params = Lists.newArrayList();
params.add( fileId );
params.add( json );
ExecutionRequest request = new ExecutionRequest().setFunction( "main2" )
.setParameters( params );
script().scripts().run( TEMPLATE_FILLER_SCRIPT_ID, request ).execute();
After enabling the logging to I was able to pull the entire web request. It all looks ~fine but maybe there's more here:
CONFIG: {"function":"main2","parameters":["15gXG9frqV0VrF57BjDqOe0pCHPWxVJ1ucV0Fl3zR0J4","{\"num\":\"035\",\"digital_key\":\"https://docs.google.com/document/d/15gXG9frqV0VrF57BjDqOe0pCHPWxVJ1ucV0Fl3zR0J4\",\"Title\":\"Build Control for Image Enhancement\",\"Author\":\"Evan Ruff\",\"Date\":\"05/11/18\"}"]}
May 11, 2018 4:59:41 PM com.google.api.client.http.HttpRequest execute
CONFIG: -------------- REQUEST --------------
POST https://script.googleapis.com/v1/scripts/1T7HAaK2yJ2qUf3sOAz3ZGSPRql73-DGCe79-dLgCyqbnh_LbIn5KgQ4r:run
Accept-Encoding: gzip
Authorization: Bearer *******MY TOKEN *********
User-Agent: Memo Builder/1.0 Google-API-Java-Client Google-HTTP-Java-Client/1.23.0 (gzip)
Content-Type: application/json; charset=UTF-8
Content-Encoding: gzip
Content-Length: 230
May 11, 2018 4:59:41 PM com.google.api.client.http.HttpRequest execute
CONFIG: curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: Bearer ya29.c.EmW4BdRkBR2JFBoDaAw_FG8DFbNCHYoe4E3jBs9HyowMAPqM2SnNky4ffRdh0zxG2nc4ylcIlr9yUHJ-ibOJuXdJhakgTmEyC7R4xn8cdKEif7mSeaeRGV9XwYI4W3AkoRAz-sCWmw' -H 'User-Agent: Micro C-Memo Builder/1.0 Google-API-Java-Client Google-HTTP-Java-Client/1.23.0 (gzip)' -H 'Content-Type: application/json; charset=UTF-8' -H 'Content-Encoding: gzip' -d '#-' -- 'https://script.googleapis.com/v1/scripts/1T7HAaK2yJ2qUf3sOAz3ZGSPRql73-DGCe79-dLgCyqbnh_LbIn5KgQ4r:run' << $$$
May 11, 2018 4:59:41 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: Total: 299 bytes
May 11, 2018 4:59:41 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: {"function":"main2","parameters":["15gXG9frqV0VrF57BjDqOe0pCHPWxVJ1ucV0Fl3zR0J4","{\"num\":\"035\",\"digital_key\":\"https://docs.google.com/document/d/15gXG9frqV0VrF57BjDqOe0pCHPWxVJ1ucV0Fl3zR0J4\",\"Title\":\"Build Control for Image Enhancement\",\"Author\":\"Evan Ruff\",\"Date\":\"05/11/18\"}"]}
May 11, 2018 4:59:41 PM com.google.api.client.http.HttpResponse <init>
CONFIG: -------------- RESPONSE --------------
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
Alt-Svc: hq=":443"; ma=2592000; quic=51303433; quic=51303432; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="43,42,41,39,35"
Cache-Control: private
Server: ESF
X-Content-Type-Options: nosniff
Content-Encoding: gzip
Vary: Referer
Vary: X-Origin
Vary: Origin
X-XSS-Protection: 1; mode=block
Date: Fri, 11 May 2018 20:59:41 GMT
Content-Type: application/json; charset=UTF-8
This seems simple enough but I'm really struggling. Any tips would be appreciated!
In case someone comes across this, Google released a Java Docs API soon after I actually got this working. The Docs API is a much nicer solution.

fiware-orion NGSIv2 update context

I created a small stack using with orion and the populated mongodb from the tour guide app.
I don't understand why the updates queries are not working :(
if I query the context:
curl -s -X GET -H "Accept: text/plain" -H "fiware-service: tourguide" 'http://localhost:1026/v2/entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/capacity/value'
I get correctly the value "50"
if I update the value, following the query examples:
curl -s -v -X PUT -H "Accept: text/plain" -H "fiware-service: tourguide" -H "Content-Type: text/plain" 'http://160.85.2.22:1026/v2/entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/capacity/value' -d 52
i get error "The requested entity has not been found. Check type and id"
* Trying 160.85.2.22...
* Connected to 160.85.2.22 (160.85.2.22) port 1026 (#0)
> PUT /v2/entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/capacity/value?type=Restaurant HTTP/1.1
> Host: 160.85.2.22:1026
> User-Agent: curl/7.47.0
> Accept: application/json
> fiware-service: tourguide
> Content-Type: text/plain
> Content-Length: 2
>
} [2 bytes data]
* upload completely sent off: 2 out of 2 bytes
< HTTP/1.1 404 Not Found
< Connection: Keep-Alive
< Content-Length: 95
< Content-Type: application/json
< Fiware-Correlator: 9d2f4164-48f3-11e6-af87-0242ac110004
< Date: Wed, 13 Jul 2016 12:16:23 GMT
<
{ [95 bytes data]
* Connection #0 to host 160.85.2.22 left intact
{
"description": "The requested entity has not been found. Check type and id",
"error": "NotFound"
}
As far as I understand, you are using the context data of the FIWARE Tour Guide Application. In that context data, Restaurant entities belong to different service paths. In particular, each Resturant belong to a service path corresponding to the value of its department attribute.
Thus, have a look to the department attribute of the 0115206c51f60b48b77e4c937835795c33bb953f entity (using the Fiware-Service header: "tourguide"). If the value of the attribute is for example "Franchise4" then you have to use the following service path header in your PUT request (pay attention to the initial /):
-H "fiware-servicepath: /Franchise4"
Why GET request on attribute value is working without service path header while PUT request on attribute value isn't? When the header is omitted, query requests default to /# (which means "any service path") while create/udpate requests default to / (which is the root service path, which doesn't match with /Franchise4).

JSON Post data empty - Linux curl Command

I am trying to post json data to php file using linux curl command, (Lamp Server)
$ curl -V -H "Content-Type: application/json" -X POST -d '{"id": "123"}'
http://localhost/crm/UpdateUser.php
In UpdateUser.php,
<?php echo var_dump ($_POST);?>
OUTPUT:
[ec2-user#ip-10-35-1-181 ~]$ curl -v -H "Content-Type: application/json" -X POST -d '{"id": "123"}' http://viacrm.odema.net/crm/UpdateUser.php
* Hostname was NOT found in DNS cache
* Trying 54.217.206.217...
> POST /crm/UpdateUser.php HTTP/1.1
> User-Agent: curl/7.36.0
> Host: 192.168.1.16
> Accept: */*
> Content-Type: application/json
> Content-Length: 13
>
* upload completely sent off: 13 out of 13 bytes
< HTTP/1.1 200 OK
< Date: Mon, 16 Jun 2014 12:25:00 GMT
* Server Apache/2.2.27 (Amazon) is not blacklisted
< Server: Apache/2.2.27 (Amazon)
< X-Powered-By: PHP/5.3.28
< Content-Length: 13
< Connection: close
< Content-Type: text/html; charset=UTF-8
<
array(0) {
}
* Closing connection 0
Always the Post data shows empty, I even tried to use "ACCEPT: application/json", still same problem. Please can anyone guide this ?
$_POST only contains the results of decoding an application/x-www-form-urlencoded request. You need to read the raw request body. If you have the always_populate_raw_post_data configuration directive turned on, then the raw body will be in $HTTP_RAW_POST_DATA; otherwise you can obtain it by reading from the php://input stream.
Instead of $_POST try it:
<?php
print($HTTP_RAW_POST_DATA);
?>