Creating multiple docytpe documents using external API in frappe framew

446 views Asked by At

I'm new to frappe framework and have been trying to use this for past week now. I wanted to create multiple doctypes from an API that returns a list of json objects from GET call. How do I do that, also help me navigate me in terms of files as I'm new to this Currently I've been editing in the <doctype>.py file

this is the code I wrote

import frappe
from frappe.model.document import Document
import requests

class todolist(Document):
    # pass
    def new_document(self):
        doctype_name = "todo-list"
        json_data = (requests.get("https://jsonplaceholder.typicode.com/todos")).json()
        for json_object in json_data:
            new_doc = frappe.get_doc({
                "doctype": doctype_name,
                "id": json_object["id"],
                "title": json_object["title"],
                "completed": json_object["completed"],
            })
        
        new_doc.insert()

whenever I run this file I get an error ModuleNotFoundError: No module named 'frappe.model'

I wanted to save the data into my doctype from an external GET request but I am getting issues with running frappe. Installed Frappe-Docker from github, created new site and app, linked both, manually created a doctype and then tried editing that python file.

1

There are 1 answers

0
Lucky On

Make sure you are using frappe version 14 or above. Here is the command to check bench version

bench --version

Command(s) to update/upgrade frape:

bench update
pip install --upgrade frappe