How to transform this json into an array

Asked

Viewed 308 times

1

I need to turn this json ( not with all fields_attribute fields) into an array in php to easily change the data

    mutation{
  createCard(
    input: {
      pipe_id: 219739
      fields_attributes: [
        {field_id: "assignee", field_value:[00000, 00001]}
        {field_id: "checklist_vertical", field_value: ["a", "b"]}
        {field_id: "checklist_horizontal", field_value: ["b"]}
        {field_id: "cpf", field_value: "123.456.789-00"}
        {field_id: "cnpj", field_value: "12.345.678/1234-00"}
        {field_id: "date", field_value: "1977-01-20"}
        {field_id: "date_time", field_value: "2017-07-20T21:00:00+00:00"}
        {field_id: "due_date", field_value: "2017-07-20T21:00:00+00:00"}
        {field_id: "currency", field_value: "9500.50"}
        {field_id: "label_select", field_value: [890073, 908006]}
        {field_id: "email", field_value: "[email protected]"}
        {field_id: "number", field_value: 9000}
        {field_id: "short_text", field_value: "Rocky Balboa"}
        {field_id: "long_text", field_value: "It ain’t about how hard you hit. It’s about how hard you can get hit and keep moving forward. It’s how much you can take, and keep moving forward. That’s how winning is done."}
        {field_id: "radio_vertical", field_value: "yes"}
        {field_id: "radio_horizontal", field_value: "no"}
        {field_id: "phone", field_value: "+55 11 1234-5678"}
        {field_id: "select", field_value: "B. Rocky Balboa II"}
        {field_id: "time", field_value: "17:25"}
      ]
      parent_ids: ["2750027"]
    }
  ) {
    card {
      id
      title
    }
  }
}

But you can’t do it when you’re like this:

        {field_id: "cpf", field_value: "123.456.789-00"}

What I’ve done so far is this:

$arr = array(
         "mutation" => array(
           "createCard" =>  array(
             "input" => array(
               "pipe_id" => "219739",
               "fields_attributes" => array(
                 "field_id" => "valore",
             ),
           ),
         ),
       ),

 );

If anyone has any doubts about JSON, it comes from the following API: pipefy

1 answer

2


That’s not a JSON and yes the format of a "request" which should be used to create a card:

Create card Mutation to create a card, in case of Success a query is returned. Request Body

In the documentation it says: Request Body (translation: Request, Request, etc.)


Using the parameters to create a card:

This way you use the method createCard to insert these parameters (as in past documentation):

createCard(input: {params})


The return of this request, now it will be a JSON:

{
  "data": {
    "createCard": {
      "card": {
        "id": "2762646",
        "title": "Rocky Balboa"
      }
    }
  }
}

To turn the return into array:

$json = // retorno da criação do card

$json_array = json_decode($json, true);

Documentation: json_decode


To see the example of request and return of the "createCard" method, click the button below the example of the link you posted (or here).

  • I noticed it after I posted it

  • No problem, the important thing is that it was solved ! :]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.