Skip to main content
Solved

GraphQL type error (python)

  • September 10, 2020
  • 2 replies
  • 591 views

bobissict
import requests
import json
url = "https://api.pipefy.com/graphql"
# Static query works
#query = """mutation{createCard( input: { pipe_id: 301421136 fields_attributes:[ {field_id: \"company_name\", field_value: \"Static Test Company\"} ] } ){ card { id title } } }"""
# Variable query to test
variables = {
    "company_name": "My Test Company"
}
query = """mutation($company_name: String){ createCard( input: { pipe_id: 301421136 fields_attributes: [{field_id: \"company_name\", field_value: $company_name} ] } ) { card { id title } } }"""
headers = {
    "content-type": "application/json",
    "authorization": "Bearer token here"
}
# Static query work
#response = requests.request("POST", url, json={"query": query}, headers=headers)
response = requests.request("POST", url, json={"query": query, "variables": variables}, headers=headers)
print(response.text)

I’m using the above code to try and create a card using a variable (company_name). The variable is a string (although in the api its listed as short_text).

 

I keep getting the following error message:

 

"errors":[{"message":"Type mismatch on variable $company_name and argument field_value (String / [UndefinedInput])","locations":[{"line":1,"column":121}],"path":["mutation","createCard","input","fields_attributes",0,"field_value"],"extensions":{"code":"variableMismatch","variableName":"company_name","typeName":"String","argumentName":"field_value","errorMessage":"Type mismatch"}}]}

 

Does anybody know how to solve this? I’m dying here :(

Best answer by Roberto Chavarria

Hi there bobissict! :smiley: 

Try this out (replacing with your values and Auth token of course) : 

import requests

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

payload = {"query": "mutation createCard($input: CreateCardInput!) {   createCard(input: $input) {     card {       id       title      }   } }",
"variables":{"input": {"pipe_id": "123456","fields_attributes": [{"field_id": "what","field_value": "FieldValue"}]}}}

headers = {
    "authorization": "Bearer authTokenHere",
    "content-type": "application/json"
}


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

print(response.text)

You need to add the GraphQL query/mutation and variables inside of a Python var like what I did using payload.

You can test out the queries/mutations while using variables on our Graphiql page here: https://app.pipefy.com/graphiql

Heres a look at what I did to test: 

 

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

2 replies

Roberto Chavarria
Pipefy Staff
Forum|alt.badge.img+5

Hi there bobissict! :smiley: 

Try this out (replacing with your values and Auth token of course) : 

import requests

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

payload = {"query": "mutation createCard($input: CreateCardInput!) {   createCard(input: $input) {     card {       id       title      }   } }",
"variables":{"input": {"pipe_id": "123456","fields_attributes": [{"field_id": "what","field_value": "FieldValue"}]}}}

headers = {
    "authorization": "Bearer authTokenHere",
    "content-type": "application/json"
}


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

print(response.text)

You need to add the GraphQL query/mutation and variables inside of a Python var like what I did using payload.

You can test out the queries/mutations while using variables on our Graphiql page here: https://app.pipefy.com/graphiql

Heres a look at what I did to test: 

 


bobissict
  • Author
  • Regular Participant
  • 1 reply
  • September 15, 2020

Thanks for your response Robert, I’ll give that a try and let you know.


Reply


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