-1

I have just started learning Python on the job in the last week. I am trying to integrate with our HR system and upload the information into Okta (our SSO provider) using the API's from each.

the HR API outputs a json file in the following format

{
    "isError": false,
    "Status": 0,
    "Message": "The request processed successfully.",
    "Result": [
        {
            "EmployeeId": {
                "DisplayValue": "004",
                "FieldHistory": []
            },
            "Title": {
                "DisplayValue": "",
                "FieldHistory": []
            },
            "FirstName": {
                "DisplayValue": "John",
                "FieldHistory": []
            },
            "LastName": {
                "DisplayValue": "Smith",
                "FieldHistory": []
            },
        }]
}

I then want to enter this into a variable called EmployeeID and put it in my code here:

PHRPayload = {
  "APIKey": PHRAPI,
  "Action": PHRAction,
  "EmployeeId": EmployeeID,
  }

I would like to iterate through the Result > EmployeeId > DisplayValue and print them into a dict and then iterate through these in another part of my code

OktaURL = "https://company.okta.com/api/v1/users/" + PHRPost.json()['Result']['EmailId']['DisplayValue']
Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
Luke W
  • 1
  • 1

1 Answers1

0

Just iterate over the result:

PHRAPI = 'yourCode'
PHRAction = 'yourCode'
data = {} #Your result from the api

for res in data['Result']:
    EmployeeID = res['EmployeeId']['DisplayValue']

    #Call API and so on
    PHRPayload = {
        "APIKey": PHRAPI,
        "Action": PHRAction,
        "EmployeeId": EmployeeID,
     }
    #....
hendrikschneider
  • 1,696
  • 1
  • 14
  • 26