I'm working on a Mapbox in creating a token access. The following code returns a list of tokens which works fine for me.
curl "https://api.mapbox.com/tokens/v2/{username}?access_token=your-access-token"
Here's my php code
$url = "https://api.mapbox.com/tokens/v2/{username}?access_token=your-access-token"
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($curl);
I was able to get a list of existing tokens with the above code. Now I need to execute the following to create a new access code.
curl -X POST "https://api.mapbox.com/tokens/v2/{username}?access_token=your-access-token"
This is exactly the same as listing of access token except, it has a -X POST. I assumed that I need to do a post with my curl function. So I add the following
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true); // added this line
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($curl);
but then I get the following error.
400 ERROR The request could not be satisfied.
What is the right way to do this? Thank you.
Never mind, I figured it out. I added the following to my code and it works. curl_setopt($curl,CURLOPT_POSTFIELDS, "");