Search code examples
reactjsreact-nativefetch-apierpnextfrappe

How to post request python method from react native?


I have a python method called def login_device(data): I tried to post request using fetch api with react native but i always get an error status of 500 and an error message of login_device() missing 1 required positional argument: 'data'

here is my fetch request

fetch(
    "url/login_device",
    {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
            loginData: credentials,
        }),
    },
)

as you can see i already pass the data in the body but i always received an error login_device() missing 1 required positional argument: 'data'


Solution

  • Since your function is defined as : def login_device(data):

    It is expecting data as a parameter in the query string.since you are using POST method you can redefine your function as

    def login_device(): data =json.loads(frappe.request.data) Here data will be a dictionary and you can access that