ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Permission Error Using Token Based Auth on REST API

bug
customization
custom_script

#1

Hai Guys, I Found Some Issue about POST Image To ERPNext using Rest API.

My case, im already create @frappe.whitelist method to upload image using python request here my code.

@frappe.whitelist()
def import_profil_image(cmd,doctype,docname,filename,isprivate,filedata,from_form):
  url = "http://xxx.xxx.com/api/method/run_custom_method"
  payload = {'cmd': cmd, 
            'doctype': doctype,
            'docname': docname,
            'filename': filename,
            'isprivate': isprivate,
            'filedata' : filedata,
            'from_form' : from_form}
  headers = {"Content-type": "multipart/form-data"}
  res = requests.post(url,data = json.dumps(payload), headers=headers)
  return res.json()

this is postman response when im post that method using default login method by erpnext

  1. Default Login Method

  2. Postman Upload Image

  3. Response Status

in case above, i success to upload image to ERPNext… but when im using token authentication response is 403 Forbidden ( Not Permitted) Output is like screenshoot below

  1. Postman Post

  2. Response Output

its something wrong with my code or something else ? can anyone help me to solve this issue ?

Thanks


#2

When you’re using token based auth, can you share what headers you’re setting? Can you also share screenshot of Headers section from Postman. Look at this related post, in this case the issue was typo with token {OP had used Token instead of token}


#3

im sorry about that, this is my header setting


#4

deleted


#5

up up up still stuck at this point