Solved

Update via GraphQL em Python

  • 15 August 2023
  • 5 replies
  • 191 views

Userlevel 7
Badge +11

Hi.

I started studying python a few days ago and I’m trying to update a card with it.

I’m trying the following code:

variables = {
"cardId": xxxxx,
"fieldId": "descri_o",
"newValue": "teste"
}

update_card_mutation = """
mutation UpdateCard ($cardId: ID!, $fieldId: ID!, $newValue: String!){
updateCardField(input: {
card_id: $cardId,
field_id: $fieldId,
new_value: $newValue
}) {
success
}
}
"""

But it returns an error:

{'errors': [{'message': 'Type mismatch on variable $newValue and argument new_value (String! / [UndefinedInput])', 'locations': [{'line': 6, 'column': 5}], 'path': ['mutation UpdateCard', 'updateCardField', 'input', 'new_value'], 'extensions': {'code': 'variableMismatch', 'variableName': 'newValue', 'typeName': 'String!', 'argumentName': 'new_value', 'errorMessage': 'Type mismatch'}}]}

I ask your help to find what I’m missing here.

icon

Best answer by Felipe Alves 15 August 2023, 22:09

View original

5 replies

Userlevel 4

Hello, @vicente-lemes. How are you?

Congratulations on starting your studies in Python. 😀🚀

Instead of using updatecard and then using updatecardfield. You can use only the updateCardField and pass the information you want to update. 

Example


variables = {
"cardId": xxxxx,
"fieldId": "descri_o",
"newValue": "teste"
}
{
updateCardField(input: {
card_id: $cardId,
field_id: $fieldId,
new_value: $newValue
}) {
success
}
}

Here is our website for developers: Pipefy Developers

Userlevel 7
Badge +11

Hello, @vicente-lemes. How are you?

Congratulations on starting your studies in Python. 😀🚀

Instead of using updatecard and then using updatecardfield. You can use only the updateCardField and pass the information you want to update. 

Example


variables = {
"cardId": xxxxx,
"fieldId": "descri_o",
"newValue": "teste"
}
{
updateCardField(input: {
card_id: $cardId,
field_id: $fieldId,
new_value: $newValue
}) {
success
}
}

Here is our website for developers: Pipefy Developers

Thanks Felipe

I tried but it returns and error:

{'errors': [{'message': 'Variable $cardId is used by  but not declared', 'locations': [{'line': 4, 'column': 14}], 'path': ['mutation', 'updateCardField', 'input', 'card_id'], 'extensions': {'code': 'variableNotDefined', 'variableName': 'cardId'}}, {'message': 'Variable $fieldId is used by  but not declared', 'locations': [{'line': 5, 'column': 15}], 'path': ['mutation', 'updateCardField', 'input', 'field_id'], 'extensions': {'code': 'variableNotDefined', 'variableName': 'fieldId'}}, {'message': 'Variable $newValue is used by  but not declared', 'locations': [{'line': 6, 'column': 16}], 'path': ['mutation', 'updateCardField', 'input', 'new_value'], 'extensions': {'code': 'variableNotDefined', 'variableName': 'newValue'}}]}

 

Userlevel 7
Badge +11

I still can’t figure out how to get out of this. If I try what you suggested it says that my variables are not declared, if I try what I showed in the first post it shows that ‘type mismatch’ error

My code:

import requests
import child_relation_pipefy_v2
import bearer

url = "https://api.pipefy.com/graphql"
bearer_token = bearer.token

extracted_id = child_relation_pipefy_v2.extracted_id

def graphql_update(query, variables=None):
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": f"Bearer {bearer_token}"
}
payload = {"query": query, "variables": variables}
response = requests.post(url, json=payload, headers=headers)
return response.json()

variables = {
"cardId": extracted_id,
"fieldId": "descri_o",
"newValue": "teste"
}

update_card_mutation = """
mutation {
updateCardField(input: {
card_id: $cardId,
field_id: $fieldId,
new_value: $newValue
}) {
success
}
}
"""

response = graphql_update(update_card_mutation, variables=variables)
print(response)

Result:

 

{'errors': [{'message': 'Variable $cardId is used by  but not declared', 'locations': [{'line': 4, 'column': 14}], 'path': ['mutation', 'updateCardField', 'input', 'card_id'], 'extensions': {'code': 'variableNotDefined', 'variableName': 'cardId'}}, {'message': 'Variable $fieldId is used by  but not declared', 'locations': [{'line': 5, 'column': 15}], 'path': ['mutation', 'updateCardField', 'input', 'field_id'], 'extensions': {'code': 'variableNotDefined', 'variableName': 'fieldId'}}, {'message': 'Variable $newValue is used by  but not declared', 'locations': [{'line': 6, 'column': 16}], 'path': ['mutation', 'updateCardField', 'input', 'new_value'], 'extensions': {'code': 'variableNotDefined', 'variableName': 'newValue'}}]}

The only way I made it work is if I fix the values of the card_id, field_id and new_value 

Userlevel 4

Hi,  @vicente-lemes. How are you?

The way to declare variables inside GraphQL is like this. You'll need to make this adjustment so that the error you showed about variables is resolved. 

 

mutation updateCardField( $cardId: ID!,$fieldId:ID!,  $newValue: [UndefinedInput]) {
updateCardField(input: {
card_id: $cardId,
field_id: $fieldId,
new_value: $newValue
}) {
success
}
}

Anything, I'll be here! 😀

Userlevel 7
Badge +11

Hi,  @vicente-lemes. How are you?

The way to declare variables inside GraphQL is like this. You'll need to make this adjustment so that the error you showed about variables is resolved. 

 

mutation updateCardField( $cardId: ID!,$fieldId:ID!,  $newValue: [UndefinedInput]) {
updateCardField(input: {
card_id: $cardId,
field_id: $fieldId,
new_value: $newValue
}) {
success
}
}

Anything, I'll be here! 😀

It worked, thanks!

Funny how it looks obvious only after you told me how to do it 😂

 

Reply