I have an API call that comes in one of three responses:
The first type of response:
[[1]]
Response [https://api.secure.com/v4/people/111548751]
Date: 2022-09-07 01:28
Status: 200
Content-Type: application/json; charset=utf-8
Size: 2.16 kB
{
"Id": 111548751,
"firstName": "Jeff",
"lastName": "Smith",
"middleName": null,
"suffix": null,
"title": null,
"sourceFileTitle": null,
"sourceFileFirstName": null,
"sourceFileMiddleName": null,
...
The second type of response:
[[1]]
Response [https://api.secure.com/v4/people/findOrCreate/]
Date: 2022-09-07 01:29
Status: 201
Content-Type: application/json; charset=utf-8
Size: 58 B
{
"Id": 111634535,
"status": "UnmatchedStored"
And finally, the third response:
[[1]]
Response [https://api.secure.com/v4/people/findOrCreate/]
Date: 2022-09-07 05:38
Status: 500
Content-Type: application/json; charset=utf-8
Size: 164 B
{
"errors": [
{
"code": "INTERNAL_SERVER_ERROR",
"text": "An unknown error occurred",
"referenceCode": "A-7731DC-490283"
}
]
Right now, these responses are stored in a list response called get_data
. I have some code sets up that extracts three pieces of data from all of these responses that looks like this:
data_log <- get_data %>%
map_df(extract, c("url", "date", "status_code"))
This will be a table that produces those three values from every response. But what I'm also trying to do is add the field Id
from all of the responses that contain the value (like the first two ones). If it doesn't contain a value for Id
(like the last response), the output would just say "No ID"