I am trying to trigger a gitlab pipeline with the below payload. I am passing JSON as a value to a predefined variable (wwww) .
{
"ref": "test_branch",
"variables": [
{"key": "xxx", "value": "abc"},
{"key": "yyyy", "value": "def"},
{"key": "zzzz", "value": "ghi"},
{"key": "wwww", "value": "{"test1" : "test2"}"}
]
}
If I trigger the gitlab pipeline with the above payload it fails with below error
curl --request POST --header PRIVATE-TOKEN: xxxxxxxxx --header Content-Type: application/json --data #sample.json https://gitlab.example.com/api/v4/projects/12345/pipeline
curl: (6) Could not resolve host: xxxxxxxxx
curl: (6) Could not resolve host: application
{"error":"The provided content-type '' is not supported."}
I know the above payload is incorrect. Can someone help with the correct method to pass JSON to a key
I have read several posts about this topic but i couldn't figure out how to send json data with curl POST on windows 10 (powershell).
I tried with \" or with """ nothing.
json data:
{
"frames": [
{
"text": "HOME2",
"icon": "i294",
"index": 0
},
{
"text": "? 65",
"icon": null,
"index": 1
}
]
}
Example of curl tries:
> curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d "{ """frames""": [{ """text""": """HOME2""", """icon""": """i294""", """index""": 0 }, { """text""": """? 65""", """icon""": null, """index""": 1 }]}"
{"error":{"code":null,"message":"Bad Request","trace":["request body must not be empty"]}}curl: (3) [globbing] bad range specification in column 2
curl: (6) Could not resolve host: text
curl: (6) Could not resolve host: HOME2,
curl: (6) Could not resolve host: icon
curl: (6) Could not resolve host: i294,
curl: (6) Could not resolve host: index
curl: (6) Could not resolve host: 0
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: text
curl: (6) Could not resolve host: ? 65,
curl: (6) Could not resolve host: icon
curl: (6) Could not resolve host: null,
curl: (6) Could not resolve host: index
curl: (6) Could not resolve host: 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
with \"
> curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d "{ \"frames\": [ { \"text\": \"HOME2\", \"icon\": \"i294\", \"index\": 0 }, { \"text\": \"? 65\", \"icon\": null, \"index\": 1 } ] }"
{"error":{"code":null,"message":"Bad Request","trace":["request body must not be empty"]}}curl: (3) [globbing] bad range specification in column 2
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: \text\
curl: (6) Could not resolve host: \HOME2\,
curl: (6) Could not resolve host: \icon\
curl: (6) Could not resolve host: \i294\,
curl: (6) Could not resolve host: \index\
curl: (6) Could not resolve host: 0
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: \text\
curl: (6) Could not resolve host: \? 65\,
curl: (6) Could not resolve host: \icon\
curl: (6) Could not resolve host: null,
curl: (6) Could not resolve host: \index\
curl: (6) Could not resolve host: 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
What am i doing wrong?
So, after further reading and from the answer from mohsen, I finalized my command line to:
curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d #exported.json
I added the json into a file called exported.json and now it is more compact and it still works.
The json data it self didn't need much more tweaking, see exported.json file:
{"frames":[{"text":"HOME2","icon":"i294","index":"0"},{"text":"? 65","icon":"null","index":"1"}]}
first minify your json here, don't use pretty json.
try this:
curl -d 'curl -d '{"frames":[{"text":"HOME2","icon":"i294","index":0},
{"text":"? 65","icon":null,"index":1}]}' -H 'Content-Type: application/json'
https://example.com/login
for more info check this site
Looks like Windows command line and PowerShell messes with curl and JSON post data. Tried the following in CMD, PowerShell and WSL. WSL gives the result I expected, the other two fails. (originally tried to post data to Node-Red, and their official example failed, that was my WTF moment)
Try this (httpbin.org just echoes your data back this case):
curl -X POST -d '{"name":"Nick","a":32}' -H "Content-type:application/json" https://httpbin.org/anything
Response when called from WSL:
{
"args": {},
"data": "{\"name\":\"Nick\",\"a\":32}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Length": "22",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.71.1"
},
"json": {
"a": 32,
"name": "Nick"
},
"method": "POST",
"origin": "*********",
"url": "https://httpbin.org/anything"
}
Response when called from CMD / PS:
{
"args": {},
"data": "'{name:Nick,a:32}'",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Length": "18",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.55.1"
},
"json": null,
"method": "POST",
"origin": "****",
"url": "https://httpbin.org/anything"
}
Notice Content-Length is different and the json property in the response is null when called from cmd or ps.
But doing this does work from both WSL and cmd, but not from PowerShell: curl -d "{\"name\":\"Nick\",\"a\":32}" -H "Content-type:application/json" https://httpbin.org/anything
And this works in PowerShell but fails in the other two curl -d '{\"name\":\"Nick\",\"a\":32}' -H "Content-type:application/json" https://httpbin.org/anything
So yes, put your post data in a file. But of course, powershell has it's own rules, so in the others you can do -d #data.json, but in powershell you must fo -d `#data.json (backtick before the # symbol)
I need to concatenate 2 variables, but when i execute the bash code i get this error filters.api.malformed_request_body.
I need to get the current IPs, to be able to add a new IP to the filter, that's because i need to use two variables, $a is the current IP that is in my firewall rule, and $b is the new IP that i will add.
From Cloudflare
To preserve existing values, issue a GET request and based on the response, determine which fields (and respective values) to include in your PUT request and that way, avoid any undesired overwrites.
Code:
a=122.16.89.10
b=137.77.77.77
curl -X PUT \
-H "X-Auth-Email: EMAIL" \
-H "X-Auth-Key: KEY" \
-H "Content-Type: application/json" \
-d '[
{
"id": "ID",
"paused": false,
"expression": "(ip.src in {'$a'" "'$b'})",
"description": "Block IP"
}
]' "https://api.cloudflare.com/client/v4/zones/ZONE/filters"
I also tried: "(ip.src in {'$a $b'})" and:
new_filter="$a $b"
...
...
"(ip.src in {'$new_filter'})"
If i echo $new_filter it shows the correct result:
new_filter="$a $b"
echo $new_filter
#122.16.89.10 137.77.77.77
When i use the variable $new_filter it also show this error curl: (3) [globbing] unmatched close brace/bracket in column 13 line 13 is this one -H "Content-Type: application/json" \.
None worked, why? I get this error:
{
"result": null,
"success": false,
"errors": [
{
"code": 10014,
"message": "filters.api.malformed_request_body"
}
],
"messages": []
}
This works: "(ip.src in {'$a'})".
Well, let's take your first example and modify it to print the JSON body:
export a=122.16.89.10
export b=137.77.77.77
echo '[
{
"id": "ID",
"paused": false,
"expression": "(ip.src in {'$a'" "'$b'})",
"description": "Block IP"
}
]'
The output is this:
{
"id": "ID",
"paused": false,
"expression": "(ip.src in {122.16.89.10" "137.77.77.77})",
"description": "Block IP"
}
]
You can see that JSON is not valid. The double quotes are unbalanced in expression.
Try "expression": "(ip.src in {'$a' '$b'})", instead -- that will produce valid JSON.
Im trying to index a simple json data in solr using curl. When i use the command, it says
"curl -X POST -H 'Content-Type:application/json'-d http://localhost:8983/solr/informationretrieval/update/json/docs '[{"id":"1","title":"Doc 1"},{"id":"2","title":"Doc 2"}]'
{"responseHeader":{"status":0,"QTime":1}}
curl: (3) [globbing] bad range specification in column 3"
I have tried removing quotes, tried -g and --globoff etc but every time there are errors like illegal port number. Can anyone please help?
Adding Multiple JSON Documents
curl -X POST -H 'Content-Type: application/json' 'http://localhost:8983/solr/informationretrieval/update' --data-binary '
[
{
"id": "1",
"title": "Doc 1"
},
{
"id": "2",
"title": "Doc 2"
}
]'
I'm getting this error:
error": { "code": 400, "message": "Invalid value at 'requests[0].image.content' (TYPE_BYTES), \"000002.jpg\"", "status": "INVALID_ARGUMENT", "details": [ { "#type": "type.googleapis.com/google.rpc.BadRequest"
And it may have something to do with the encoding of the images, not sure. I am sending Google a bunch of .jpgs.
Note that this is similar to this question, but that one doesn't help a whole lot - there's no answer.
Here's my JSON:
for f in $FILES
do
echo "Original file name is $f"
response=$(curl -v -H "Accept: application/json" -H "Content-type:
application/json" -X POST -d '{"requests":[
{
"image":{
"content":"'"$f"'"
},
"features":[
{
"type":"LABEL_DETECTION",
"maxResults":3
}
]
}]}' $baseURL)
echo $response
done
This is the first image I send it.
Any thoughts on what's causing this?
You need to send the base64 encoded representation of the image, not the filename.