Skip to main content
Solved

Update via GraphQL em Python


Forum|alt.badge.img+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.

Best answer by Felipe Alves

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

View original
Did this topic help you find an answer to your question?

5 replies

Felipe Alves
Pipefy Staff
  • Enterprise Support Analytics
  • 27 replies
  • Answer
  • August 15, 2023

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


Forum|alt.badge.img+11
felipealves wrote:

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'}}]}

 


Forum|alt.badge.img+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 


Felipe Alves
Pipefy Staff
  • Enterprise Support Analytics
  • 27 replies
  • August 24, 2023

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! 😀


Forum|alt.badge.img+11
felipealves wrote:

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 😂

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings