Skip to main content
Solved

Mutation - Bad Request - .NET Core


wesbalbino

Hi everyone! How is it going?

I’m wondering if anyone could help with a problem that I have been facing.

I’m trying to create a card on one of my pipes using .NET but I keep getting BadRequest every time. But the strange thing is that I’m using the same query on a REST client and it works every time.

 

Could someone please help me with this?

 

 

var jsonString = "{ \"query\": \"mutation{createCard(input:{pipe_id:302295485 title:\"title\" fields_attributes:[{field_id:\"texto_form\", field_value:\"valor_form\"}]}){ card{id title}}}}";
 

 

 

Best answer by wesbalbino

Hey man!

 

The issue is that you need to escape the quotes around the fieldId valur and around the fieldValue.

 

"mutation { createTableRecord(input:  { table_id: 302428234, fields_attributes: { field_id: \"" + fieldId + "\" field_value: \"" + fieldValue + "\" }}) { table_record { id }}}";

 

Try this query 

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

13 replies

Naoki
Pipefy Staff
  • Pipefy Staff
  • 2 replies
  • March 22, 2022

Hi @wesbalbino,

I have a question about your session. Do you log in when you try to POST in our API?

The REST client is working because you are authenticated in another browser’s tab.


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 15, 2022
Naoki wrote:

Hi @wesbalbino,

I have a question about your session. Do you log in when you try to POST in our API?

The REST client is working because you are authenticated in another browser’s tab.

Hi Naoki, I have excactly the same problem.

It works great in Postman, but not in C#.

It is NOT a session problem because if I replace the query that works in Postman with

            string query = "{\"query\": \"{ me { id email } }\"}";

it works fine.

 

Our entire sales pipeline with hubspot CRM integration project is stalled because of this bug and we would love some help.

 

I would be happy to provide an example C# project for you to study and reproduce the issue.

 

 


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 15, 2022

Also, there are no more details provided from the API what could be the problem. It just says “Bad request”. It does appear that it is the “field_id” that is the problem, (string vs ID! type (what ever that is in a json string???))  but I’m not sure.


wesbalbino
  • Author
  • Regular Participant
  • 4 replies
  • May 15, 2022

Hey everyone! My problem was actually being caused by the .NET lib that I was using (RestSharp). I had the idea to use another lib (GraphQL.Client and GraphQL.Client.Serializer.Newtownsoft) and everything worked as expected.

Hope this helps you @jakob-nystrom  :)


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 15, 2022
wesbalbino wrote:

Hey everyone! My problem was actually being caused by the .NET lib that I was using (RestSharp). I had the idea to use another lib (GraphQL.Client and GraphQL.Client.Serializer.Newtownsoft) and everything worked as expected.

Hope this helps you @jakob-nystrom  :)

I actually switched from RestSharp because I had problems getting the graphQL Client to work, I ended up with serialization errors and bla bla.

Could you be so kind and post a working code snippet with a mutation database table query like the one in your first post? I would really appreciate that!!

That said, RestSharp SHOULD work but yeah if I can get it to work with the GraphQL Client Library that would be even better


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 16, 2022

 Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

 

This error above was indeed beacuse of a session error, when switching back to GraphQLClient I had omitted the authorization header: 

 

graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Configuration.GetValue<string>("PipefyApiToken")}" );

 

I am getting something back, let’s see if I can get the data I actually want now


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 16, 2022
wesbalbino wrote:

Hey everyone! My problem was actually being caused by the .NET lib that I was using (RestSharp). I had the idea to use another lib (GraphQL.Client and GraphQL.Client.Serializer.Newtownsoft) and everything worked as expected.

Hope this helps you @jakob-nystrom  :)

 

So, this is what I am getting. Given that the querystring is a STRING, why on earth does the Pipefy API complain that it wants an ID! type?!?!?!

This STRING works great in Postman for me. Not using Restsharp, not using GraphQLClient.

 

			var fieldId = "text";
            var fieldValue = "test2000";
			var meRequest = new GraphQLRequest {
				Query = "mutation { createTableRecord(input: { table_id: 302428234, fields_attributes: { field_id: " + fieldId + ", field_value: " + fieldValue + " } }) { table_record { id }}}"
			};
            try {
                var me = await graphQLClient.SendQueryAsync<TableRecordResponseType>(meRequest);
                Log.Debug(JsonConvert.SerializeObject(me, Formatting.Indented));
            }
            catch (Exception ex) {
                Log.Debug(ex.Message);
                if (ex.InnerException != null) { Log.Debug(ex.InnerException.Message); }
            }
 "statusCode": 200,
  "data": null,
  "errors": [
    {
      "locations": [
        {
          "column": 79,
          "line": 1
        }
      ],
      "message": "Argument 'field_id' on InputObject 'FieldValueInput' has an invalid value (text). Expected type 'ID!'.",
      "path": [
        "mutation",
        "createTableRecord",
        "input",
        "fields_attributes",
        0,
        "field_id"
      ],
      "extensions": {
        "code": "argumentLiteralsIncompatible",
        "typeName": "InputObject",
        "argumentName": "field_id"
      }
    },
    {
      "locations": [
        {
          "column": 79,
          "line": 1
        }
      ],
      "message": "Argument 'field_value' on InputObject 'FieldValueInput' has an invalid value (test2000). Expected type '[UndefinedInput]'.",
      "path": [
        "mutation",
        "createTableRecord",
        "input",
        "fields_attributes",
        0,
        "field_value"
      ],
      "extensions": {
        "code": "argumentLiteralsIncompatible",
        "typeName": "InputObject",
        "argumentName": "field_value"
      }
    }
  ],

 


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 16, 2022

OK so right now I have boiled down the issue to this:

 

This WORKS, it creates an entry in the database:

 

var meRequest = new GraphQLRequest {
    Query = "mutation { createTableRecord(input: { table_id: 302428234, fields_attributes: { field_id: \"text\" field_value: \"test2000\" } }) { table_record { id }}}"

};

 

This does NOT work, it gives the errors outlined in previous reply, expecting ID! type and UndefinedInput type. The difference is I am using variables in the string.

var fieldId = "text";
var fieldValue = "test2000";
var meRequest = new GraphQLRequest {
    Query = "mutation { createTableRecord(input: { table_id: 302428234, fields_attributes: { field_id: " + fieldId + ", field_value: " + fieldValue + " } }) { table_record { id }}}"
			};

This also does NOT work, ( { are escaped by using double {{ and  }} respectively)

var fieldId = "text";
var fieldValue = "test2000";
var meRequest = new GraphQLRequest {
    Query = $"mutation {{ createTableRecord(input: {{ table_id: 302428234, fields_attributes: {{ field_id: {fieldId} field_value: {fieldValue} }} }}) {{ table_record {{ id }}}}}}"
			};

 

Of course, using variables is an absolute must.

@pipefy_api  Why would the API accept hardcoded strings but not string variables in a string query? 


wesbalbino
  • Author
  • Regular Participant
  • 4 replies
  • May 16, 2022

Hey Jakob! :)

I’ll take a look at your code and I’ll get back to you


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 16, 2022
wesbalbino wrote:

Hey Jakob! :)

I’ll take a look at your code and I’ll get back to you

 

Hey, appreciate it, but this turned out as well to be a GBTW issue (Garbage Behind The Wheels)

When changing to variables. I did not keep the escaped quotes \”

 

var meRequest = new GraphQLRequest {
	Query = $"mutation {{ createTableRecord(input: {{ table_id: 302428234, fields_attributes: {{ field_id: \"{fieldId}\" field_value: \"{fieldValue}\" }} }}) {{ table_record {{ id }}}}}}"
            };

 This actually works =)

Hope this helps someone else

 


wesbalbino
  • Author
  • Regular Participant
  • 4 replies
  • Answer
  • May 16, 2022

Hey man!

 

The issue is that you need to escape the quotes around the fieldId valur and around the fieldValue.

 

"mutation { createTableRecord(input:  { table_id: 302428234, fields_attributes: { field_id: \"" + fieldId + "\" field_value: \"" + fieldValue + "\" }}) { table_record { id }}}";

 

Try this query 


jakob-nystrom
  • Participating Frequently
  • 8 replies
  • May 16, 2022
wesbalbino wrote:

Hey man!

 

Thanks for taking a look. Yes I just realized it, 1 minute before you posted, look above =) =) =) 


wesbalbino
  • Author
  • Regular Participant
  • 4 replies
  • May 16, 2022
jakob-nystrom wrote:
wesbalbino wrote:

Hey man!

 

Thanks for taking a look. Yes I just realized it, 1 minute before you posted, look above =) =) =) 

No problem! I’m glad everything worked out as expected :)

 

 


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