API with Python

mikecaputozimikecaputozi Expensify Customer Posts: 2 Expensify Newcomer

I'm trying to build an integration to update employees' managers using the Expensify API with Python. I need to know how to attach the CSV file containing the employees to be updated. I see how to do it with curl, but I can't quite figure out how to translate that to Python. Should it be another key in the JSON data? If so, what's the key name?

Here is the Python code I have so far:

import requests as req

import json

import csv


class Expensify:

    apiurl = "https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations"

  user = "..."

  secret = "..."

  policyid = "..."


  def getbasemessage(self, action="update", objecttype="employees") -> dict:

    base = {

      "requestJobDescription": {

        "type": action,

        "credentials": {

          "partnerUserID": self.user,

          "partnerUserSecret": self.secret

        },

        "inputSettings": {

          "type": objecttype,

          "policyID": self.policyid,

          "fileType": "csv"

        }

      }

    }


    return base


  def sendmessage(self, msg):

    result = req.post(self.apiurl, data=json.dumps(msg), headers="Expect:")

    return result


  def usermanagerupdate(self, employeeemail, manageremail):

    msg = self.getbasemessage()

    d = {

      "EmployeeEmail": employeeemail,

      "ManagerEmail": manageremail,

      "Admin": False

    }

    with open("temp.csv", "w") as f:

      w = csv.DictWriter(f, d.keys())

      w.writeheader()

      w.writerow(d)


    # How do I get the file in here?

    self.sendmessage(msg)

Tagged:
Sign In or Register to comment.