Link to home
Start Free TrialLog in
Avatar of Matthew B
Matthew BFlag for Canada

asked on

Simple POST with cURL Sheel Script

When i execute this cURL command from my linux ubuntu CLI it executes as a GET instead of a POST request. What am i doing wrong here? I cant figure it out and its driving me insane!

Also this WORKS in postman, but when i run the exact cURL shell from postman i get a 400 from the API, the vendor is unable to specify what the issue is.

curl 
-v 
-POST
 -H 'Accept: */*'
 -H 'Accept-Encoding: gzip,deflate' 
-H 'Cache-Control: no-cache' 
-H 'Host: api.mapbox.com'
 -H 'content-type: multipart/form-data; boundary=——WebKitFormBoundary7MA4YWxkTrZu0gW'
 -form file=@/home/matt/test.geojson.ld 
--url 'https://api.mapbox.com/tilesets/v1/sources/achuhealth/mack-testing1?access_token=TOKEN'

Open in new window

Avatar of David Favor
David Favor
Flag of United States of America image

Try -X POST instead.

The -POST option seems to be consumed by curl with no error + is an error, so a bit confusing.
Avatar of noci
noci

-X POST is needed or --data  which implies POST.

--data is probably  what you are actually looking for.
Avatar of Matthew B

ASKER

Hi David,

I simplified my request but got a new error:

new request

curl -v -X POST "https://api.mapbox.com/tilesets/v1/sources/achuhealth/hello-world?access_token=TOKEN" \ -F file=@/home/matt/test.geojsnon.ld \ --header "content-Type: multipart/form-data"

Open in new window


error

* Connection #0 to host api.mapbox.com left intact
{"message":"No file data in request. Expected 1 file named \"file\"."}* Rebuilt URL to:  -F/
* Could not resolve host:  -F
* Closing connection 1
curl: (6) Could not resolve host:  -F
* Could not resolve host:
* Closing connection 2
curl: (6) Could not resolve host:
* Rebuilt URL to:  --header/
* Could not resolve host:  --header
* Closing connection 3
curl: (6) Could not resolve host:  --header
* Could not resolve host: content-Type
* Closing connection 4
curl: (6) Could not resolve host: content-Type

Open in new window

also here is the direct example from the API docs

$ curl -X POST "https://api.mapbox.com/tilesets/v1/sources/achuhealth/hello-world?access_token=YOUR_MAPBOX_ACCESS_TOKEN" \
    -F file=@/Users/username/data/mts/countries.geojson.ld \
    --header "Content-Type: multipart/form-data"

Open in new window

Something seems incorrect with you escaping.

The above command works fine for me (without data return as access_token is invalid) using latest Ubuntu + latest bash shell.

Mention the OS + shell you're using, also provide output of...

curl --version

Open in new window

curl  "https://api.mapbox.com/tilesets/v1/sources/achuhealth/hello-world?access_token=YOUR_MAPBOX_ACCESS_TOKEN"  \
     --data file=@/Users/username/data/mts/countries.geojson.ld

Open in new window


Should also work...
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.