• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

    • ⚠️ Got a Something went wrong message? Read this guide and provide the actual error. Do not skip this.
    • ✅ Confirm that the server meets the System Requirements
    • 🔥 Check for any available Hotfix - your issue could be already reported/fixed
    • 📚 Read documentation - It will be required to Debug and understand Errors for a faster support response

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

mattgphoto

Chevereto Member
🎯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:
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>
 
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?
 
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.
 
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"
}
 
(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)
 
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)
 
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 🙂
 
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:
2ISyBOD
 
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.
 
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.
 
In that case, then you should use app/routes/overrides/route.api.php override. That will save you the trouble of adding the other stuff needed.
 
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?
 
I'm sorry to hear about that. Revert it back and maybe ask someone to do it for you. Otherwise just keep trying I guess.
 
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?
 
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.

[CODE lang="php" title="app/routes/overrides/route.api.php L104"] $uploaded_id = CHV\Image::uploadToWebsite($source, 'admin');[/CODE]

That's all, really. Just tested.

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

Attachments

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?
 
In software development is normal to encounter bugs, wrong documentation, performance issues, incompatible resources, etc. I'm sorry if I wasn't clear about this in the beginning, of course that I noted that the issue here is that loader.php has some conditionals targeting /api and that's why any API in a different path won't work as expected. In certain conditions, the custom APIs won't work and that was caused by the changes introduced later on to that file so the documentation was outdated.

I've fixed the documentation and I've also indicate this caveat for those that want to run multiple APIs for Chevereto V3.

Hope you understand my weird workflow and sorry for any headache you had because of this.
 
Back
Top