How to get Curl header response? - html

I am trying to get the below response from my curl command. My command inserts data into a list and that works perfectly. However, I cannot seem to figure out how to get the below response.
curl -d "{"""name""":"""ME""","""id""":1}" -H "Content-Type: application/json" -X PUT http://localhost:8081/api/users
I have tried all of the following.
curl --trace, curl -v, curl -i, curl -w '%{response_code}'
DEBUG 2018-11-26 16:15:24,853 [http.listener.06 SelectorRunner] [event: ]
org.mule.service.http.impl.service.HttpMessageLogger.HTTP_Listener_config: LISTENER
PUT /api/users HTTP/1.1
Host: localhost:8081
User-Agent: curl/7.54.0
Accept: */*
Content-type:application/json
Content-Length: 18
{"name":"ME","id":1}
DEBUG 2018-11-26 16:15:24,861 [[MuleRuntime].cpuLight.03:
[troubleshooting_myapi].troubleshooting_myapiFlow2.CPU_LITE #541c15d] [event:
0-a0773d60-f1af-11e8-9c18-70886b824af4]
org.mule.service.http.impl.service.HttpMessageLogger.HTTP_Listener_config: LISTENER
HTTP/1.1 200
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 26 Nov 2018 19:15:24 GMT
a9
[
{
"name": "ME",
"id": 1
}
]

Try with -D -.
This is what curl -h says about header options
-D, --dump-header <filename> Write the received headers to <filename>
The - instead of filename indicates the stdout.
curl -D - -d "{"""name""":"""ME""","""id""":1}" -H "Content-Type: application/json" -X PUT http://localhost:8081/api/users

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

Failed conversion from dwg to svf with the Autocad api TranslationWorker

I am failing to upload a simple dwg and convert it to svf using the TranslationWorker from the forge API. I am using autocad 2014 and creating a simple drawing with a circle and saving it as a .dwg.
I am using the commandline in windows and the following curl commands:
curl -v "https://developer.api.autodesk.com/oss/v2/buckets/kumkortbucket/objects/sirkel.dwg" -X "PUT" -H "Authorization: Bearer OAUTH_TOKEN" -H "Content-Type: application/octet-stream" -T "‪C:\Users\DAN\Documents\Testfiler\sirkel.dwg"
which produces the following result:
HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Authorization, Accept-Encoding, Range,Content-Type
< Access-Control-Allow-Methods: GET
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Date: Tue, 14 Feb 2017 12:56:38 GMT
< Server: Apigee Router
< Content-Length: 355
< Connection: keep-alive
<
{
"bucketKey" : "kumkortbucket",
"objectId" : "urn:adsk.objects:os.object:kumkortbucket/sirkel.dwg",
"objectKey" : "sirkel.dwg",
"sha1" : "78f92dc0a364814756cfa9392d7fa95aecf0916b",
"size" : 31548,
"contentType" : "application/octet-stream",
"location" : "https://developer.api.autodesk.com/oss/v2/buckets/kumkortbucket/objects/sirkel.dwg"
}* Connection #0 to host developer.api.autodesk.com left intact
I then convert it using the POST job command
curl -X "POST" -H "Authorization: Bearer OAUTH_TOKEN" -H "Content-Type: application/json" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/job" -d "{\"input\": {\"urn\": \"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldC9zaXJrZWwuZHdn\"},\"output\": {\"formats\": [{\"type\": \"svf\",\"views\": [\"2d\",\"3d\"]}]}}"
Using the GET command to check the result i get the following result:
{"type":"manifest","hasThumbnail":"false","status":"failed","progress":"complete","region":"US","urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldC9zaXJrZWwuZHdn","version":"1.0","derivatives":[{"name":"sirkel.dwg","hasThumbnail":"false","status":"failed","progress":"complete","messages":[{"type":"error","code":"AutoCAD-InvalidFile","message":"Sorry, the drawing file is invalid and cannot be viewed. \n- Please try to recover the file in AutoCAD, and upload it again to view."},{"type":"error","message":"Unrecoverable exit code from extractor: -1073741831","code":"TranslationWorker-InternalFailure"}],"outputType":"svf"}]}* Connection #0 to host developer.api.autodesk.com left intact
I cannot figure out what i am doing wrong. I can view the file in autocad and the online viewer.
Cheers.
EDIT:
here is a file that is problematic to upload
http://www.filedropper.com/ekbsroplain
Here is what I did (entire process):
curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' -X 'POST' -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=****&client_secret=****&grant_type=client_credentials&scope=data:read data:write data:create bucket:create bucket:read'
curl -v 'https://developer.api.autodesk.com/oss/v2/buckets' -X 'POST' -H 'Content-Type: application/json' -H 'Authorization: Bearer TOKEN' -d '{"bucketKey":"kumkortbucket170214","policyKey":"transient"}'
Note I'm uploading without content-type and content-length, not need actually:
curl -v 'https://developer.api.autodesk.com/oss/v2/buckets/kumkortbucket170214/objects/drawing1.dwg' -X 'PUT' -H 'Authorization: Bearer TOKEN' -T '/Users/augustogoncalves/Desktop/Drawing1.dwg'
And finally the POST JOB:
curl -X 'POST' -H 'Authorization: Bearer TOKEN' -H 'Content-Type: application/json' -v 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' -d '{"input":{"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldDE3MDIxNC9kcmF3aW5nMS5kd2c="},"output":{"formats":[{"type": "svf","views": ["2d","3d"]}]}}'
And worked fine
{
"result":"success",
"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a3Vta29ydGJ1Y2tldDE3MDIxNC9kcmF3aW5nMS5kd2c",
"acceptedJobs":{
"output":{
"formats":[
{
"type":"svf",
"views":[
"2d",
"3d"
]
}
]
}
}
}

CURL to POST to JIRA

I am using curl command in powershell in my Windows machine. I am trying to create an issue in JIRA which I have installed in my local. I tried following but it throws me error. Can someone let me know what am I missing and how to fix it?
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data $parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*curl: (6) Could not resolve host: Content-Type
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
X-AREQUESTID: 770x749x1
X-ASEN: SEN-L8183526
Set-Cookie: JSESSIONID=D0B4391C94413FDDB1291C419F3E1360; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B3EL-GHY4-P1TP-IMD0|d3d735e0a6566f8a97f99c96e80042551def3192|lin; Path=/
X-ASESSIONID: 1v4terf
X-AUSERNAME: raji
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Sun, 10 Jul 2016 07:20:36 GMT
*
When I try following I get this error:
PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data #parse.json -H
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**
*At line:1 char:38
+ curl -D- -u raji:raji -X POST --data #parse.json -H "Content-Type: ap ...
+ ~~~~~~
The splatting operator '#' cannot be used to reference variables in an expression. '#parse' can be used only as an argument to a command. To reference variables in an expression use '$parse'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermitted*
And hence I tried $ instaed of # in file name.
"parse.json" File has following content:
{
"fields": {
"project":
{
"key": "Demo"
},
"summary": "REST ye merry gentlemen",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
As this is windows machine, I also tried using slash (/) in parse.json file (saw in few posts that / will remove the error) but that also did not help. Please can someone let me know how to fix this?
In the first case
curl -D- -u raji:raji -X POST --data $parse.json -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
$parse is interpreted by powershell as variable, $parse.json as attribute json of the variable $parse, which does not exist, so the command executed would be
curl -D- -u raji:raji -X POST --data -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
data is -H, and the content type header is interpreted as url to access.
In the second case the # in powershell is interpreted as splat operator, if you want a literal # (which is interperted by curl and not by powershell), simply quote the string:
curl -D- -u raji:raji -X POST --data "#parse.json" -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue
Now it should use the contents of the file parse.json as data.

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);
?>