0

I'm trying to pass the following body to my POST request via httr:

{
    "transactionId": "55",
    "IncidentNumber": "",
    "customerEmailAddress": "pbi_cqd@example.com",
    "customerName": "Power BI CQD Notifications",
    "customerPhoneNumber": "",
    "customerAgency": "Agency",
    "customerSiteId": "1234",
    "incidentPriority": "3",
    "problemSummary": {
        "synopsis": "Call Quality Analytics: Issue detected",
        "description": "test"
    }
  }

The request works in Postman.

In R, however, I'm receiving the error "Error: object of type 'closure' is not subsettable". I'm not sure that I'm setting this up correctly, as there is a nested structure to the body:

URL <- paste0(InstanceURL, API_EndPoint)

Problem_summary <- list(
                        synopsys = "Call Quality Analytics: Issue detected", 
                        description = "test"
                    )

Full_body <- list(
            transactionId = "55", 
            IncidentNumber = "", 
            customerEmailAddress = "pbi_cqd@example.com", 
            customerName = "Power BI CQD Notifications", 
            customerPhoneNumber = "", 
            customerAgency = "Agency", 
            customerSiteId = "1234", 
            incidentPriority = "3", 
            problemSummary = Problem_summary
             ) %>% jsonlite::toJSON(pretty = TRUE)

Incident <- POST(URL, body = Full_body, encode = "json", handle = handle)

Any suggestions? If it helps, this is the ServiceNow REST API to create a new incident.

Thanks in advance!

Alienvolm
  • 143
  • 9
  • 1
    Did you define `handle` somewhere? – MrFlick May 18 '22 at 18:22
  • Ouch... no! What should that be? – Alienvolm May 18 '22 at 18:35
  • 1
    If you aren't overriding that parameter, just leave it out. Try just `Incident <- POST(URL, body = Full_body, encode = "json")` – MrFlick May 18 '22 at 18:38
  • Without handle I get this error: Error in curl::curl_fetch_memory(url, handle = handle) : Failure when receiving data from the peer – Alienvolm May 18 '22 at 18:46
  • 1
    Also don't use `%>% jsonlite::toJSON(pretty = TRUE)` on your `Full_body` if you are using `encode = "json"`. That will happen automatically. Hard to tell exactly what's happening without any sort of [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that we can run and test with. It's unclear what the server is returning. – MrFlick May 18 '22 at 18:51
  • Hi, I spent some time testing and in the end I believe it was the API itself not being configured correctly in ServiceNow. I tried with a different API and the script works just fine! Thanks a lot for the help! – Alienvolm May 18 '22 at 20:22

0 Answers0