How to make ShareX upload images/screenshots as my user via the api?

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
ğŸŽ¯Description of the issue

When trying to upload screenshots to my chevereto install as my user via ShareX with the myapi workaround, it fails.

▶🚶‍Reproduction steps
  1. Following this guide: https://chevereto.com/docs/api-v1#api-user
  2. I have in the ShareX destination settings as follows: https://m.purrbox.org/2ITJKin
  3. If I change that URL to: https://pics.domain.com/myapi/1/upload it fails.
  4. Here is what is in my app/routes/overrides/route.myapi.php:
// CHV\Image::uploadToWebsite($source, 'username', [params]) to inject API uploads to a given username
$uploaded_id = CHV\Image::uploadToWebsite($source, 'myuser');
$json_array['status_code'] = 200;
$json_array['success'] = array('message' => 'image uploaded', 'code' => 200);
$json_array['image'] = CHV\Image::formatArray(CHV\Image::getSingle($uploaded_id, false, false), true);


😢Unexpected result

I'm not using anything fancy like postman to test this further, but the upload fails. Is there a different key I should be using besides what is in Dashboard > Settings > API?
 
Last edited:

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
16,674
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
ShareX is agnostic about the actual URL you use in their settings so if the API URL works in Postman it will also work on browser, ShareX or any HTTP client. You have to use the *hacked* API URL, not the default /api/

To understand better how to help you, you should post the response that you get from the upload endpoint. To easy test it, use ?upload=<some image url>
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Hey Rodolfo, no problem! So I guess with this then, I have a few questions:
1. What is the 'hacked' API URL?
2. And does this mean I should be deleting the app/routes/api.php file in order for the route override?
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
16,674
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
Please, read the instructions carefully. https://chevereto.com/docs/api-v1

API user upload workaround
API V1 one doesn't have a way to upload images associated with a given user but Chevereto comes ready for route overriding and you can easily customize your own API that can accomplish this task. Copy the default app/routes/route.api.php file to something like app/routes/overrides/route.myapi.php folder. We will do our job in this new route.myapi.php file.
 
  • Like
Reactions: Saxtus

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Ah ha. Ok, so doing some testing with the API in postman now as well. I've added the app/routes/overrides/route.myapi.php file (copied as directed from the routes folder), but I'm seeing this:
1. The /myapi url doesn't exist.
2. When I do just /api with the new key I put in the php file, it gives this:
{
"status_code": 400,
"error": {
"message": "Invalid API v1 key.",
"code": 100,
"context": "Exception"
},
"status_txt": "Bad Request"
}
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
(Now obviously if I used the default API key generated from the dashboard, it works). I've also reloaded php/nginx since I added this new route in the overrides folder)
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
16,674
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
Please forget about /api, you are working with /myapi now.

2266

If you did that, then it should work right away. If is not the case, then try restarting services (maybe your rewrite module is giving you issues)
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Sorry about that, just was running into a roadblock with the /myapi url, so will have to look into that when I get back home and adjust reverse proxy as necessary :)
 
  • Like
Reactions: Rodolfo

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Ok, so I took a look tonight using the direct url of the server, this is what my post call looks like in postman:

Code:
http://192.1.1.1/myapi/upload/?key=randomcharacters&action=upload&source=http://thewowstyle.com/wp-content/uploads/2015/02/Beautiful-Wallpapers-14.jpg&format=json
But it's returning the HTML for the login page for my chevereto install. Here's my query params:
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
16,674
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
You also need to add a bunch of placeholders to app/loader.php.

Are you planning running as single user? if that's the case use route.api.php instead of route.myapi.php.
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Hey Rodolfo, I haven't forgotten about this I promise. I've come down with a cold and am trying to recover. Once I feel better I'll let you know when I can troubleshoot this again. But to answer your question, this is just going to be an install for me and one other user. I'll be the only one using ShareX with it.
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Hey Rodolfo! Feeling better finally. Coming back to this now. So at this point I have a route.myapi.php in it with everything I'd mentioned so far and it is in '/var/www/html/app/routes/overrides'. So instead I should `mv route.myapi.php route.api.php` (in that directory) and then reload php/web server and should be able to upload to /api and it will upload as my user assuming I use the right api key?
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
Did that, and it broke the upload via sharex entirely.
 

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
So if that's the end of trying to get the documentation to work (and it doesn't)... is there someone who HAS used the documentation successfully, and if not, guess we just wait until the next version of chev to come out where the API won't need a hack to be more flexible?
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
16,674
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
I could answer to you the same thing that every company says to me in a situation like this. "We're sorry, we are looking forward to address this issue in the future". But I'm not a company, and I will appreciate if you understand that I don't have the resources to pick the phone and put a guy to fix the API user thing.

Attached is the file that you have to place in app/routes/overrides/route.api.php. Literally I touched one single line.

app/routes/overrides/route.api.php L104:
        $uploaded_id = CHV\Image::uploadToWebsite($source, 'admin');
That's all, really. Just tested.

P.S. Do please change 'admin' with the actual target username.
 

Attachments

mattgphoto

Core license
License owner
Joined
Apr 11, 2019
Messages
11
Points
53
I do understand that you are just one person, it's one of those things though where if there's documentation available from you that it's expected to work. And perhaps we strayed away from that documentation is why it didn't work. Not sure. FYI the instruction you JUST gave worked perfectly. That worked just fine. I assume that's only to be used if you have one user who wants to do this, as opposed to multiples with their own keys, etc. Multiples is where we ran into issues?