Using REST API Directly from PHP (no lib)


#1

I’d like to perform both “storage” and “delete” commands on single images from my server using PHP. Since these seem like they should be simple operations, I’d like to just use the REST API directly and not use the uploadcare PHP lib if possible. (It’s just one more github package I’d have to worry about keeping up with changes on, etc.)

I’m not super fluent with CURL, so I was hoping someone could tell me how to perform the following command using PHP.

curl -H “Authorization: Uploadcare.Simple demopublickey:demoprivatekey”
-X PUT
https://api.uploadcare.com/files/03ccf9ab-f266-43fb-973d-a6529c55c2ae/storage/

Thanks in advance for any help!


#2

You may want to look at how the lib does these requests under the hood and take parts that you actually need:


#3

Just in case someone else has a similar need, this is what ended up working for me:

$cSession = curl_init(); 

curl_setopt($cSession, CURLOPT_URL,"https://api.uploadcare.com/files/03ccf9ab-f266-43fb-973d-a6529c55c2ae/storage/");
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($cSession, CURLOPT_HTTPHEADER, array('Authorization: Uploadcare.Simple demopublickey:demoprivatekey')); 
curl_setopt($cSession, CURLOPT_RETURNTRANSFER,true);

$result = curl_exec($cSession);							// $result holds details about the file that was stored
$status = curl_getinfo($cSession, CURLINFO_HTTP_CODE);	// $status will be 200 if the api call was successful

curl_close($cSession);