I want to automate a process where I want to convert a JSON file to a YAML file particularly in the format of Swagger YAML. I have tried python and npm libraries but they dont give the same YAML. Is there a Swagger REST API to do the job?
The REST way-
curl -X POST \
https://generator3.swagger.io/api/generate \
-H 'content-type: application/json' \
-d #file-name.json -o result.zip
Or else
curl -X POST \
https://generator3.swagger.io/api/generate \
-H 'content-type: application/json' \
-d '{
"spec" : "Key1: Value1, Key2: Value2",
"lang" : "openapi-yaml",
"type" : "CLIENT",
"codegenVersion" : "V3"
}' -o result.zip
Related
I'd like to create a custom link via the API, that's to say instead of maclede12.co/3R8OeCm maclede12.co/magnifique. It is also referred as custom back-half.
I'm able to patch a link with the API via this request:
curl \
-H 'Authorization: Bearer token' \
-H 'Content-Type: application/json' \
-X PATCH \
-d '{
"id": "maclede12.co/3R8OeCm",
"custom_bitlinks": [
"maclede12.co/magnifique"
],
"tags": [
"bitly",
"api"
]
}' \
https://api-ssl.bitly.com/v4/bitlinks/maclede12.co/3R8OeCm
The tags are updated but I'm not able to get a custom link. The custom_bitlinks parameter comes from the doc but is it still even possible to do it?
The following script of curl command works fine with variables inside double-quoted string, but how do I use variables (e.g. ip_address and user_id) inside the --data-raw '{...}'?
#!/bin/sh
ip_address="10.0.0.1"
user_id="my-user-id"
websec_token="some_string"
version="v12"
curl -w #curl-format.txt \
--request POST "http://example.com/$version/web" \
--header "Authorization: Bearer $websec_token" \
--header "Content-Type: application/json" \
--data-raw '{
"ipAddress": "10.0.0.1",
"userId": "my-user-id"
}'
Just escape the double quotes:
--data-raw "{
\"ipAddress\": \"$ip_address\",
\"userId\": \"$user_id\"
}"
just add single quote arround the var part is better, as less \ introduced :
--data-raw '{
"ipAddress": "'$ip_address'",
"userId": "'$user_id'"
}'
I need to call an API where I increment the user ID every time, I have the following in the bash script, but keep getting a Unexpected token ' in JSON at position 2 error. What am I doing wrong?
for ((i=1;i<=5;i++)); do
curl -X POST --header 'Content-Type: application/json' -d "{ 'id': 'person'$i, 'name':
'person', 'info': {} }" 'http://localhost:9999/add'
It is a quoting issue. It is standard for JSON to have double quotes, try this
for ((i=1;i<=5;i++)); do
echo "Adding person"$i
curl -X POST --header 'Content-Type: application/json' --header
'Accept: application/json' --user 'admin' -d '{ "id": "person'$i'", "name":
"person", "info": {} }" 'http://localhost:9999/add'
done
You can use jq, to edit json by shellscript. See this link.
i want to to know to where and how to run a json format like this
curl --request POST \
--url https://x.com/xxxx \
--header 'apikey: xxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'content-type: application/json' \
--data '{
"filter": {
"whois_name": "xxxxxxxxx"
}'
You can run it from the terminal in a computer which has the cUrl utility installed.
I'm attempting to create an issue on github using curl.
If there is any Chinese character exist in the json, it always returns "Problems parsing JSON".
curl -i -H 'Authorization: token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{ \
"title": "sfsd", \
"body": "We should have one", \
"labels": ["中文"] \
}' \
https://api.github.com/repos/user/repo/issues