Solved

Phyton Mutation

  • 24 August 2020
  • 8 replies
  • 558 views

Userlevel 4

I have probleme with create record in a table, I use the code bellow, but its not working the payload string….. 

 

import requests

url = 'https://app.pipefy.com/graphiql'

payload = "{\"query\":\"{mutation {createTableRecord(input: {table_id: "n1kpekCb", title: "my record", due_date: "2017-12-31T00:00-03:00", fields_attributes: [{field_id: "nombre", field_value: "Tom"}, {field_id: "apellido_paterno", field_value: "tom@trindade.com"}, {field_id: "apellido_materno", field_value: "Trindade"}, {field_id: "n_documento", field_value: "Tom"}, {field_id: "correo_electronico", field_value: "tom@trindade.com"}, {field_id: "telefono_celular", field_value: "tom@trindade.com"}, {field_id: "estado", field_value: "Activo"}, {field_id: "vendedor", field_value: "Sí"}, {field_id: "comprador", field_value: "Sí"}, {field_id: "arrendador", field_value: "Sí"}, {field_id: "arrendatario", field_value: "Sí"}]}) { table_record { id title due_date record_fields { name value } } } }\"}"

headers = {
    'authorization': 'Bearer Token',
    'content-type': 'application/json'
    }

print(payload)

response = requests.post(url, data=payload, headers=headers)

print(response)

icon

Best answer by Marcos Carvalho 2 September 2020, 16:26

View original

8 replies

Userlevel 6
Badge +6

 Hey Gonzalo,

You’re missing some escaping in the payload string. Here an example with the backslashes before double quotes on field_id and field_value:

 

payload = "{\"query\":\"mutation {   createTableRecord(input: {table_id: \\\"pE_m-KeD\\\", fields_attributes: {field_id: \\\"o_qu\\\", field_value: \\\"Creating table record\\\", field_id: \\\"texto1\\\", field_value: \\\"Another field value\\\"}}) {     clientMutationId     table_record {       id     }   } }\"}"

 

If you want the response payload to have back the card information, try using requests.request like this:

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

 

 

Here the complete mutation example:

 

import requests

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

payload = "{\"query\":\"mutation { createTableRecord(input: {table_id: \\\"pE_m-KeD\\\", fields_attributes: {field_id: \\\"o_qu\\\", field_value: \\\"Creating table record\\\", field_id: \\\"texto1\\\", field_value: \\\"Another field value\\\"}}) { clientMutationId table_record { id } } }\"}"
headers = {
'authorization': "Bearer TOKEN",
'content-type': "application/json"
}

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

print(response.text)

 

 

Pipefy Developers page has this console that can help you adding all the escapes you need in Python:

 

https://developers.pipefy.com/reference#graphql-endpoint

 

 

 

Hope it helps you :grinning:

Userlevel 4

Thanks @Marcos Carvalho  for the information.

The next problem right now it is how i update the records, can you send me a example for python.

 

Userlevel 6
Badge +6

Hey Gonzalo, 

 

Here are some mutations to update the Table Record information. 

 

mutation {
updateTableRecord(input: {id: 383338802, title: "teste"}) {
clientMutationId
}
}

 

If you need to update the Table Record Value, here’s the mutation:

mutation {
updateFieldsValues(input: {nodeId: 383338802, values: {fieldId: "texto", value: "Send another value"}}) {
clientMutationId
}
}

 

 

And here both examples in Python:

 

import requests

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

payload = {"query": "mutation { updateTableRecord(input: {id: 383338802, title: \"teste\", statusId:\"late\"}) { clientMutationId } }"}
headers = {
"authorization": "Bearer YOUR_TOKEN",
"content-type": "application/json"
}

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

print(response.text)

 

import requests

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

payload = {"query": "mutation { updateFieldsValues(input: {nodeId: 383338802, values: {fieldId: \"texto\", value: \"Send another value\"}}) { clientMutationId } }"}
headers = {
"authorization": "Bearer YOUR_TOKEN",
"content-type": "application/json"
}

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

print(response.text)

 

 

Hope it helps you

Userlevel 4

Hi Marcos, thanks for all…

Di you know hoy to send a new Due Date value en Python, I have problem with the definition of the new value?, I dont understand the structure of the date value? 

Userlevel 6
Badge +6

Hey Gonzalo, 

 

Pipefy has two Date formats. Here are they:

  • Date:  {field_id: "date", field_value: "1977-01-20"}

          

  • Datetime:  {field_id: "date_time", field_value: "2017-07-20T21:00:00+00:00"}

 

Due dates uses the same format as Datetime, so the structure is: 

{field_id: "due_date", field_value: "2017-07-20T21:00:00+00:00"}

 

Userlevel 4

Hi Marcos,

what it is the T21? how i define un python? 

2017-07-20T21:00:00+00:00

thanks for the quickly answer

Userlevel 6
Badge +6

Hi Gonzalo, 

 

The T is for Time. In this example is for the hour (21:00).

 

Here an example in Python. 

import requests

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

payload = {"query": "mutation{ createCard( input: { pipe_id: 219739 fields_attributes: [ {field_id: \"due_date\", field_value: \"2017-07-20T21:00:00+00:00\"} ] parent_ids: [\"2750027\"] } ) { card { id title } } }"}
headers = {
"authorization": "Bearer YOUR_TOKEN",
"content-type": "application/json"
}

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

print(response.text)

 

Userlevel 4

greats!, thanks!

I am working on this!

Reply