Curl command for creating Github Repository is not working - json

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

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.

How to get Curl header response?

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

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.

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"
]
}
]
}
}
}

Rails app on Heroku - Issue with CORS

I have a Rails app on Heroku with this configuration:
module MyAppApi
class Application < Rails::Application
# other configs
config.middleware.use Rack::Cors do
allow do
origins '*'
resource '*',
:headers => :any,
:methods => [:get, :post, :delete, :put, :options]
end
end
end
end
My problem is that any request returns with a 301 status. For example:
$ curl \
-i -H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X OPTIONS 'http://myappapi.heroku.com/api/v1/resource.json'
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 17 May 2013 14:56:00 GMT
Content-Length: 0
Connection: keep-alive
Location: http://myappapi.heroku.com/api/v1/resource.json
Same response for GET, POST. Any ideas of what is happend here? Thanks in advance.
You are requesting to .heroku.com domain. Try to request to ".herokuapp.com" instead
https://devcenter.heroku.com/articles/error-codes#h16-redirect-to-herokuappcom