How can I get a response from "frappe.make_get_request('https://example.com'

I’ve implemented a server side script to call external service via rest api. Here is my code.

frappe.make_get_request(‘https://jsonplaceholder.typicode.com/posts/10’)

I think this call is working but I have no idea how to get the response for my rest call. Could you please help me to get the response?

Thank you in advance.

Hello jaekim, have you learned how to get its response, I’m with the same problem here today :sweat_smile:

What is the issue here. You can simply check by printing the response you get. PFA for your reference.

1 Like

Thanks again Sandeep, I’ve found this System console as well, where I could test my logic, and make it work the way I needed it to work.

But now I’ve gone into a new problem, that I need to send an Image file itself, to an endpoint as a data, but from Server Script I can’t use “open()” method from Python, to read the image and then send it as an Image.

Perhaps, Would you know any other methods that I could use to solve my problem, any tips? haha

In server scripts, imports are disabled for security reasons. So for this you have to code this in your app.
There is one method which you can use, but it returns the bytes string of the file, for which you need to create a function on the other server to convert it back to image. Below is the example code.

file_doc = frappe.get_doc("File", {"file_name"})
bytes = file_doc.get_content()
1 Like

Hello Sandeep,

I could solve that returning the base64 string, but I had to overwrite a method in frappe, that wasn’t working properly, the method in frappe.utils.image_to_base64().

Then I could make it work, and get the base64, I tried your way there but didn’t succeed, maybe I’ve used the wrong file_name haha.

But thanks a lot again for your kind and help!

1 Like

How did you overwrite the method. Can you share here what exactly you did, for others looking for same solution.

1 Like

@jaekim , Try this.
frappe.response[‘message’] = res

Sure Sandeep, the orignal method wasn’t working for me, so I just got the image’s path and used the lib base64 to convert the image to base64.

I’ll send the original method here:
image

And the method I overwrote like this:
image

For me that worked, so I could get the base64 from the image!

1 Like