Skip to main content
Solved

How to interate through all cards with Python in Pipefy

  • July 28, 2020
  • 4 replies
  • 1622 views

Nigel O'connell
Pipefy Staff

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!

Best answer by Marcos Carvalho

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])

 

4 replies

Marcos Carvalho
Pipefy Staff
Forum|alt.badge.img+6
  • Pipefy Staff
  • 55 replies
  • Answer
  • July 28, 2020

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])

 


m.sabadini
  • Inspiring
  • 5 replies
  • December 1, 2020

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? 

 


Marcos Carvalho
Pipefy Staff
Forum|alt.badge.img+6
  • Pipefy Staff
  • 55 replies
  • December 3, 2020

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 


m.sabadini
  • Inspiring
  • 5 replies
  • December 4, 2020

Super tks Marcos! 

 

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