[Solved] cURL example of a whitelist method RPC call with parameters?

The user guide for the RPC API describes only the trivial case: a call with out parameters.

I’d be grateful if someone would provide a complete cURL example with the required headers, authentication etc.

Ok I figured it out:

# sudo apt install jq;
export ERP_KEY="2604a8329cb8834";
export ERP_SCT="7b5f5e8f6bd262b";
export MY_HOST="your.host";
curl -s -X POST "http://${MY_HOST}/api/method/frappe.core.doctype.file.file.get_files_in_folder" \
        -H "Authorization: token ${ERP_KEY}:${ERP_SCT}" \
        -H 'Content-Type: application/json' \
        --data-raw '{ "folder": "Home" }' \
  | jq -r .;


The response is :

{
    "message": [
        {
            "name": "a21dead99",
            "file_name": "Logo.jpg",
            "file_url": "/private/files/Logo.jpg",
            "is_folder": 0,
            "modified": "2020-05-01 16:24:38.073539"
        }
    ]
}

I got the API method from @revant_one 's wonderful resource: A GitHub Gist: erpnext-whitelisted-endpoints - ‘frappe.core.doctype.file.file.get_files_in_folder(folder)’


Extra – How to get the Authorization token:

So the Key is : 2604a8329cb8834
and the Secret is: 7b5f5e8f6bd262b

Test the API RPC interface…

# sudo apt install jq;
export ERP_KEY="2604a8329cb8834";
export ERP_SCT="7b5f5e8f6bd262b";
export MY_HOST="your.host";
curl -s -X POST "http://${MY_HOST}/api/method/frappe.auth.get_logged_user" \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -H "Authorization: token ${ERP_KEY}:${ERP_SCT}" \
        | jq -r .

.With the result…

{
  "message": "Administrator"
}
3 Likes