rahy
January 19, 2021, 11:50pm
1
Is there any step by step guidance on how to use the frappe’s REST API from authorization until doing the task?
I found there are 3-4 pages in frappe.io , frappeframework.com , and Frappe · GitHub but they are all pieces of information which I can’t relate the methods explained.
I also found some websites maintain by users but they are for advance use.
I need it because i’m not an advance user and just learning to code.
Thank you.
rahy
January 20, 2021, 4:41am
2
For example,
#1 . I do this returns the expected result (from Simple Authentication ):
curl -X POST https://my.domain.com/api/method/login \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"usr":"Administrator","pwd":"admin"}'
#2 . and doing this:
https://my.domain.com/api/method/login?usr=Administrator&pwd=admin
also return as expected {"message":"Logged In","home_page":"/desk","full_name":"Administrator"}
#3 . but doing this:
requests.post('https://my.domain.com/api/method/login', auth=("Administrator", "admin"))
return <Response [401]>
EDIT :
The correct one for this is:
params = (
('usr', 'Administrator'),
('pwd', 'admin'),
)
requests.post('https://my.domain.com/api/method/login', params=params)
that will give <Response [200]>
#4 . and doing:
fetch('http://my.domain.com/api/method/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
usr: 'Administrator',
pwd: 'admin'
})
})
.then(r => r.json())
.then(r => {
console.log(r);
})
return result: TypeError: Not allowed to request resource
But the last one is js, right?
jervz09
January 21, 2021, 12:05am
3
Hello . Try this Frappe Ajax Call
@frappe.whitelist()
rahy
January 21, 2021, 12:58am
4
Thanks @jervz09 ,
I actually want to do it on python. But I’ll certainly take a look at that page also.
we can login using simple authentication but same url showing error with token based authentication, why so?
Thanks