0
How to implement a R & Graphql process that verifies the existence of next pages by combining the results?
I described a process that returns OK when the query is a text but returns error when I try to compose the received variable in the first query to get the following pages
- The text of the queries for POST in Graphql is declared without the use of the backslash " "
- The PASTE operation places the exhaust sequences
- The first query is OK but the second returns status 400
- However, the same query, with double quotes only in the endCursor value returns OK no when performed in Graphql or via Postman
For this reason, I suspect that the error received in the second query is related to formatting the escape sequences
References: Pagination (Handling multi-page Sponses) in https://rdrr.io/cran/httr/f/vignettes/api-packages.Rmd
[1] connected setup and queries
base_url <- "https://app.pipefy.com/queries"
token_api <- "Bearer eyJ0eXAiOJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1c2VyIjp7ImlkIjozMDEwMzM3NzQsImVtYWlsIjoiY2FybG9zLm9saXZlaXJhanVuaW9yQGNsYXJvLmNvbS5icisImFwcGxpY2F0F0aW9uIjozMDAwODMzDJ9fQ.L---------------ETC...
initial consultation
consulta_node <- '{"query":"{allCards(pipeId:301370952 first:50){pageInfo {hasNextPage endCursor}edges {node {id title fields { indexName report_value}}}}}"}'
terms of the following consultations for the interim argument of next page
consulta_node1 <- '{"query":"{allCards(pipeId:301370952 first:50 after:"'
query_node2 <- '"){pageInfo{hasNextPage endCursor}edges{Node{id title current_phase{id name}Fields{indexName name report_value}}}}}"}'
[2] perform the first query and get the information for next pages
consulta_node
res_api <- POST( url = base_url, add_headers(.headers = c("Content-Type"="application/json","Authorization"=token_api), body = query node, Encode = "json", Handle = NULL)
res_api
Response [https://app.pipefy.com/queries] Date: 2021-02-25 09:37 Status: 200 Content-Type: application/json; charset=utf-8 Size: 99.8 kB
resposta_json <- fromJSON(rawToChar(res_api$content), Flatten = TRUE,)
recovers data received
endCursor <- resposta_json[["date"]][["allCards"][["pageInfo"][["endCursor"]] endCursor
[1] "Wyizljailci3ljaildm4odixodu2of0"
hasNextPage <- resposta_json[["date"]][["allCards"][["pageInfo"]["hasNextPage"]] hasNextPage
[1] TRUE
[ 3] assemble next query including endCursor
the following queries <- Paste(querie_node1, endCursor, consult_node2, Sep = "") following consultations
executes the query with indication of next page
res_api <- POST( url = base_url, add_headers(.headers = c("Content-Type"="application/json","Authorization"=token_api), body = following queries, Encode = "json", Handle = NULL)
res_api
Response [https://app.pipefy.com/queries] Date: 2021-02-25 09:37 Status: 400 Content-Type: text/html; charset=utf-8