Received Data from other application

Dear All
I want to integrate with other applications, I created a custom app with a custom doctype
I want to read all data from the other application and save it in erpnext

Sample Request:

{
“pageNumber”: 1,
“pageSize”: 50, “data”: {
“timeZoneOffset”: -120,
“fromDate”: “2020-11-22”,
“toDate”: “2020-11-23”,
“displayType”: 1
}
}

Sample Response:

{
“data”: {
“list”: [
{
“jobNumber”: “0”, “userName”:“h.shqeer@t2.sa”, “fullName”: "heba ",
“totalPlanWorkHourDuringInterval”: “00:00”,
“totalHoursWorkDuringInterval”: “00:01”,
“totalCheckInLateHoursDuringInterval”: “00:00”,
“totalCheckOutLateHoursDuringInterval”: “00:00”, “workReportTransactions”: {
“list”: [
{
“selectedDate”: “2020-11-22T00:00:00”,
“status”: “Completed”, “workingHours”: “-”,
“checkInDate”: “17:56”, “checkInAccessGateNameAr”: “heba”, “checkInAccessGateNameEn”: “gps”, “checkOutDate”: “17:57”, “checkOutAccessGateNameAr”: “heba”, “checkOutAccessGateNameEn”: “gps”, “actualWorkingHours”: “00:01”,
“sessionTotalCheckInLateHours”: “00:00”,
“sessionTotalCheckOutLateHours”: “00:00”,
“sessionTotalShortesHours”: “00:00”,
“sessionTotalOverTimeHours”: “00:00”,
“sessionTotalOverTimeExtraHours”: “00:00”,
“sessionTotalHolidayOverTimeHours”: “00:00”
}
],
“totalCount”: 2
}
}
],
“totalCount”: 3
},
“status”: true, “message”: "

how i can do this

Hi:

You need to manage this connection with a backend method in Python. Call external API using requests library:

import requests

def get_data_from_api(url):
  response = requests.get(url)
  data = response.json()
  return data

Note that maybe you need some authentication work before … and you will need to extract data properly and fit it in your doctype …

Inserting data is easy with frappe API methods.

doc = frappe.new_doc('Your doctype)
doc.yourfield1 = 'Your data1'
doc.yourfield2 = 'Your data2'
doc.insert()

Here some inspiration:

Hope this helps.

1 Like

All this time I was scared of API integrations and never tried to learn it. Recently I took the effort and help from the community to learn API integration and it was freakin easy.

@avc has provided a good example.

Here is a little project I did with APIs

import frappe
import time
import asyncio

import requests
from requests.auth import HTTPBasicAuth
from requests.exceptions import HTTPError

enable = frappe.db.get_single_value('Razorpay API Settings', 'enable')
key_id = frappe.db.get_single_value('Razorpay API Settings', 'key_id')
key_secret = frappe.db.get_single_value('Razorpay API Settings', 'key_secret')
from_account = frappe.db.get_single_value('Razorpay API Settings', 'account_number')

auth = HTTPBasicAuth('apikey', 'apisecret')

def payout_composite_bank_account(**payout_info):

    ## Documentation : https://razorpay.com/docs/api/x/payout-composite ##

    # mode = "NEFT"
    # amount =  round(1, 2) * 100
    # purpose = "payout"
    # account_name = "ZARNIK HOTEL SUPPLIES PRIVATE LIMITED"
    # account_number = "2339261005253"
    # account_ifsc = "CNRB0002339"
    # contact_name = "Rahul Jayan"
    # contact_email = "rahul@zarnik.com"
    # contact_mobile = "7736060114"
    # contact_type = "vendor"
    # contact_reference = "V00023"
    # payment_reference = "TEST"
    # narration = "TEST"

    mode = str(payout_info["mode"])
    amount = int(float(payout_info["amount"]) * 100)
    purpose = str(payout_info["purpose"]) 
    account_name = str(payout_info["account_name"]) 
    account_number = str(payout_info["account_number"]) 
    account_ifsc = str(payout_info["account_ifsc"] )
    contact_name = str(payout_info["contact_name"]) 
    # contact_email = str(payout_info["contact_email"])
    # contact_mobile = str(payout_info["contact_mobile"]) 
    contact_type = str(payout_info["contact_type"])
    contact_reference = str(payout_info["contact_reference"]).replace("-"," ")
    payment_reference = str(payout_info["payment_reference"]) .replace("-"," ")
    narration = str("ZARNIK " + str(payout_info["contact_reference"]).replace("-"," ") + " " + str(payout_info["payment_reference"]).replace("-"," "))

    url = "https://api.razorpay.com/v1/payouts"
    headers = {"X-Payout-Idempotency" : ""}

    payload = {
            "mode": mode,
            "amount": amount,
            "purpose": purpose,                         
            "currency": "INR",
            "narration": narration,
            "fund_account": {
                "account_type": "bank_account",
                "bank_account": {
                    "name": account_name,
                    "ifsc": account_ifsc,
                    "account_number": account_number
                },
                "contact": {
                    "name": contact_name,
                    # "email": contact_email,
                    # "contact": contact_mobile,
                    "type": contact_type,
                    "reference_id": contact_reference
                }
            },
            "reference_id": payment_reference,
            "account_number": str(from_account),
            "queue_if_low_balance": bool(1)
            }

    if enable == 1:
        try:
            response = requests.request("POST", url, auth=auth, headers=headers, json=payload)
            print(response.text)
            return response

        except HTTPError as http_err:
            frappe.log_error(message=f'{http_err}',title="RazorpayX HTTP Error")
            print(response.text)
            return response

        except Exception as err:
            frappe.log_error(message=f'{err}',title="Razorpayx Payout Composit API Error")
            print(response.text)
            return response

def fetch_transaction_by_id(payout_id="xyz"):

    ## Documentation : https://razorpay.com/docs/api/x/transactions#fetch-transaction-by-id ##

    if enable == 1:
        if payout_id:
            try:
                url = "https://api.razorpay.com/v1/payouts/"+payout_id
                response = requests.request("GET", url, auth=auth)
                print(response.json())
                return response

            except HTTPError as http_err:
                frappe.log_error(message=f'{http_err}',title=f'RazorpayX HTTP Error: {payment_order}')
                print(response.json())
                return response

            except Exception as err:
                frappe.log_error(message=f'{err}',title=f'RazorpayX: {payment_order}')
                print(response.json())
                return response
4 Likes

Is there any way to link attendance application (paypagar) with erpnext

Hi:

If the software to connect have any mechanism like API endpoint, database, exported file … to get data from or send data to … then you can connect it (technically at least …)

Anyway, i can’t found any information about Paypagar (seems just a mobile app …?).

Hope this helps.

Yes a mobile app with live location to take the attend for the employees outside

You will have to ask the company if they have APIs

1 Like

Has anyone coded an API call to a service using OAuth2?

I’d love some pointers in this regard. Thanks so much.

Can you please give some idea on how erpnext and DELMIA Works IQMS application can be integrated. Delmia Works has WEB api. I want to integrate that api with ERPnext. Kindly give some ideas to achieve this.

Hey Azhar,
I just need your help. I have delmiaWorks application webapi. I want to integrate with erpnext application. Kindly help me where i have to put that code. Please!

@SrinivasanS2307 Please DM me, we can discuss on WhatsApp or Call.