(Restful API) Help me to write code for HTTP Post/Get

112 views
Skip to first unread message

rahul nejanawar

unread,
Jul 8, 2014, 7:22:19 AM7/8/14
to erpnext-dev...@googlegroups.com
Hi all,
 
1. I wrote a python code for login using Post and here is the  link of my code http://pastiebin.com/53bbce75204fc . When i execute this code it will give output as  {"message":"Logged In","full_name":"Administrator"}. I think it is right as given in https://frappe.io/apps/frappe-framework/developers/api/rest_api.
2. After that i tried above with ruby code ie http://pastiebin.com/53bbd0729431c it gives output like usr=Administrator&pwd=admin
{"message":"Logged In","full_name":"Administrator"}
200
3. After that i tried to Post the reorder quantity(re_order_qty) for a particular item(in ruby)  and here is the link of my code http://pastiebin.com/53bbd20f59ce8. When i execute this code it will give out put as usr=Administrator&pwd=admin
{"message":"Logged In","full_name":"Administrator"}
200
email_id=sam_sd%40gmail.com
{}
200

In the above out put i not received any response(the response field is empty {}). I tried this in python code also and i found the out put as {}. Here is the link of my python code http://pastiebin.com/53bbd398d84c4 .
4. How to get the response of my code to know that Post operation successful. Please help me to write code for that.

hassan bellounis

unread,
Jul 8, 2014, 9:05:23 AM7/8/14
to erpnext-dev...@googlegroups.com
The login method takes as form data the user and the password, whereas the resource takes a dict named data as parameter


The proper way should be to send as form data :
{
data : {
       //Your data
    }
}


Also POST request are for creating document. So you shouldn't send a name to the document (LEAD0006)
If you're trying to fetch the document send a GET request.

rahul nejanawar

unread,
Jul 8, 2014, 10:55:58 AM7/8/14
to erpnext-dev...@googlegroups.com
Thank you hassan,

Here I tried Get  http://pastiebin.com/53bc058a14df3 but I m getting 403 error by executing this code. So please correct me I m new to erpnext. And also please give me some examples for Post/Get.  

Rushabh Mehta

unread,
Jul 9, 2014, 1:23:13 AM7/9/14
to erpnext-dev...@googlegroups.com
On 08-Jul-2014, at 8:25 pm, rahul nejanawar <rahulne...@gmail.com> wrote:

Thank you hassan,

Here I tried Get  http://pastiebin.com/53bc058a14df3 but I m getting 403 error by executing this code. So please correct me I m new to erpnext. And also please give me some examples for Post/Get.  


On Tuesday, July 8, 2014 6:35:23 PM UTC+5:30, hassan bellounis wrote:
The login method takes as form data the user and the password, whereas the resource takes a dict named data as parameter


The proper way should be to send as form data :
{
data : {
       //Your data
    }
}


Also POST request are for creating document. So you shouldn't send a name to the document (LEAD0006)
If you're trying to fetch the document send a GET request. 



Le mardi 8 juillet 2014 13:22:19 UTC+2, rahul nejanawar a écrit :
Hi all,
 
1. I wrote a python code for login using Post and here is the  link of my code http://pastiebin.com/53bbce75204fc . When i execute this code it will give output as  {"message":"Logged In","full_name":"Administrator"}. I think it is right as given in https://frappe.io/apps/frappe-framework/developers/api/rest_api.
2. After that i tried above with ruby code ie http://pastiebin.com/53bbd0729431c it gives output likeusr=Administrator&pwd=admin
{"message":"Logged In","full_name":"Administrator"}
200
3. After that i tried to Post the reorder quantity(re_order_qty) for a particular item(in ruby)  and here is the link of my code http://pastiebin.com/53bbd20f59ce8. When i execute this code it will give out put as usr=Administrator&pwd=admin
{"message":"Logged In","full_name":"Administrator"}
200
email_id=sam_sd%40gmail.com
{}
200

In the above out put i not received any response(the response field is empty {}). I tried this in python code also and i found the out put as {}. Here is the link of my python code http://pastiebin.com/53bbd398d84c4 .
4. How to get the response of my code to know that Post operation successful. Please help me to write code for that.


-- 
Note:
 
If you are posting an issue,
1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
--- 
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/8a8b347d-af74-478c-9821-2e2d0ba395a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rahul nejanawar

unread,
Jul 9, 2014, 8:18:49 AM7/9/14
to erpnext-dev...@googlegroups.com
Thank you rushabh for the link,
I used frappeclient.py to do a simple GET for an Item. (Note: I already had an item name 'Plywood' in my localhost ERPNext installation. So I am trying to get this.)

Please find my code in the below link. The code has two parts (1) FrappeClient (2) our code using the client to do a GET. To look at my code (2), please scroll down to the bottom.

My code when run, responds with code 403. Also a server traceback which you can find in http://pastie.org/9371349

Appreciate if someone could look into my code and let me know what is the mistake.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.

Rushabh Mehta

unread,
Jul 10, 2014, 12:03:30 AM7/10/14
to erpnext-dev...@googlegroups.com
Looks like you are not passing cookies correctly


To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/b90253b8-de3d-49d8-9a49-19f2197b0f4d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages