I have a batch API that is pulling staff information from our school management system. The API call works well in other applications, but in Power Automate there's something strange going on.
When running the flow, it gives me an error that the MiddleName field is expecting a string, but returning a null. In the dataset, there are some teachers with no middle name listed, so the field is null. This is making the flow fall over, but I am not sure how to fix this step.
I am looking to send the output from this into a Microsoft List so that teachers can look up the contact details of other staff (apparently looking in Outlook or the school management system is too hard for them, so maybe this will work for them...)
Below is JSON Schema based on the sample I provided to the flow from the sample.
{
"type": "object",
"properties": {
"iSAMS": {
"type": "object",
"properties": {
"HRManager": {
"type": "object",
"properties": {
"CurrentStaff": {
"type": "object",
"properties": {
"StaffMember": {
"type": "array",
"items": {
"type": "object",
"properties": {
"@@Id": {
"type": "string"
},
"@@PersonId": {
"type": "string"
},
"@@PersonGuid": {
"type": "string"
},
"Initials": {
"type": "string"
},
"UserCode": {
"type": "string"
},
"Title": {
"type": "string"
},
"Forename": {
"type": "string"
},
"MiddleNames": {
"type": "string"
},
"Surname": {
"type": "string"
},
"FullName": {
"type": "string"
},
"NameInitials": {
"type": "string"
},
"PreferredName": {
"type": "string"
},
"Salutation": {
"type": "string"
},
"DOB": {
"type": "string"
},
"Gender": {
"type": "string"
},
"SchoolEmailAddress": {
"type": "string"
},
"SchoolMobileNumber": {},
"PersonalMobileNumber": {},
"TeachingStaff": {
"type": "string"
},
"Divisions": {
"type": "object",
"properties": {
"Division": {
"type": "array",
"items": {
"type": "object",
"properties": {
"@@Id": {
"type": "string"
},
"Name": {
"type": "string"
}
},
"required": [
"@@Id",
"Name"
]
}
}
}
},
"Roles": {
"type": "object",
"properties": {
"Role": {
"type": "object",
"properties": {
"@@Id": {
"type": "string"
},
"Name": {
"type": "string"
}
}
}
}
},
"PreviousMISId": {
"type": "string"
},
"UserName": {
"type": "string"
},
"LeavingDate": {
"type": "string"
}
},
"required": [
"@@Id",
"@@PersonId",
"@@PersonGuid",
"Initials",
"UserCode",
"Title",
"Forename",
"Surname",
"FullName",
"NameInitials",
"PreferredName",
"Salutation",
"DOB",
"Gender",
"SchoolEmailAddress",
"SchoolMobileNumber",
"TeachingStaff",
"Divisions"
]
}
}
}
}
}
}
}
}
}
}
Fantastic @Expiscornovus
That cracked it....
I found that putting this snippet of code then removes it from being available to the list, so I removed the null from the type section...
"MiddleNames": { "type": ["string","null"]}
It then sprung into life!
Thanks again!
Hi @Always_Flying,
The Apply to each expects an array. However, the body is an object.
As a workaround can you place square brackets around the body and try again?
@Expiscornovus thank you so much for that pointer!
I applied that logic to the "MiddleNames" and several other fields, which have all worked. There was also a later array nested within an object that was originally object within object. Played around using those same principles, which appear to have worked for that step....
And now we have another snag, which I feel is connected to the array within an object?
Hi @Always_Flying,
You can amend your parse json schema to allow null values for certain properties.
April Dunnam has a nice blog about this approach:
https://www.sharepointsiren.com/2018/10/flow-parse-json-null-error-fix/
For example MiddleNames
"MiddleNames": { "type": "string" }
Can be converted to something like below
"MiddleNames": { "type": ["string","null"]}
WarrenBelz
146,552
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,928
Most Valuable Professional