Solved

How to interate through all cards with Python in Pipefy

  • 28 July 2020
  • 4 replies
  • 1210 views

Userlevel 5

Hi! I'm working in a python script that read some fields from all cards from a pipe and them write it to pandas in Python. The main idea is to iterate through all key values from json list.
Here's my code:

import requests
import jsonurl = ""https://api.pipefy.com/graphql""payload = ""{\""query\"":\""{ allCards (pipeId:127682, first:50) { edges { node { id title fields { name report_value updated_at value } } } }} \""}""
headers = {
'authorization': ""Bearer ""my_token"""",
'content-type': ""application/json""
}response = requests.request(""POST"", url, data=payload, headers=headers)
print(response.text)Since here, all it's ok.But when I try to parse it with json with this code:json_dic=json.loads(response.text)for key in json_dic:
print (key,"":"",json_dic[key])I just got an another list like the first ""print"", it seems that ""response.text""

is not a dict object, so when I parse it with json.loads, script can't identify the keys and separate them.Whats going wrong?Thx!

icon

Best answer by Marcos Carvalho 28 July 2020, 20:46

View original

4 replies

Userlevel 6
Badge +6

Hey Nigel, 

 

It’s necessary to access the dictionary elements before iterate it. 

 

You can access the edges

['data']['allCards']['edges'][0]

 

Or node fields: 

['data']['allCards']['edges'][0]['node']['fields'][0]

 

 

Here an example in Python:

import requests
import json


url = "https://api.pipefy.com/graphql"

payload = "{\"query\":\"{ allCards (pipeId:127682, first:50) { edges { node { id title fields { name report_value updated_at value } } } }}\"}"
headers = {
'authorization': "Bearer YOUR TOKEN",
'content-type': "application/json"
}

response = requests.request("POST", url, data=payload, headers=headers)

dic=json.loads(response.text)['data']['allCards']['edges'][0]['node']['fields'][0]

for key in dic:

print(key, ":", dic[key])

 

Userlevel 3

Hi all, 

What about to list ALL cards? not firts 50th.

 

I`ve trying using first, last, after, before… nothing that helps to list all cards or to ‘paginate’.

 

Any idea? 

 

Userlevel 6
Badge +6

Hey @m.sabadini ,  

 

We need to use pagination in order to keep Pipefy infrastructure safe. 

 

To paginate you need to use pageInfo attribute. 

 

 

{
allCards(pipeId: 987654) {
edges {
node {
id
}
}
pageInfo {
endCursor
}
}
}

 

 

In the response payload you’ll get a string to use in your next query: 

 

      ],
"pageInfo": {
"endCursor": "WyIyLjgyODEyNSIsIjI5MC4wIiwzNzc4MzQ5MDld"
}
}
}
}

 

 

Like this: 

 

{
allCards(pipeId: 987654, after:"WyIyLjgyODEyNSIsIjI5MC4wIiwzNzc4MzQ5MDld") {
edges {
node {
id
}
}
pageInfo {
endCursor
}
}
}

 

 

Hope it helps you  =D 

Userlevel 3

Super tks Marcos! 

 

that is it! It works like a charm...

Reply