Search code examples
c#.netflurl

Nested values with POST using Flurl


So I'm a Ruby dev messing with C# and trying to figure out how to use Flurl with my endpoint.

Here's the JSON I can pass successfully with Ruby.

  {
    type: "workorder.generated",
    data: [{
        id: order.id,
        type: "orders"
      },{
        id: second_order.id,
        type: "orders"
      },{
        id: bad_order.id,
        type: "orders"
      }
    ]
  }

So using C# with Flurl I'm not 100% on how to structure that.

var response = await GetAPIPath()
    .AppendPathSegment("yardlink_webhook")
    .WithOAuthBearerToken(GetAPIToken())
    .PostJsonAsync(new
    {
        type = "workorder.generated",
        data = new
        {

        }

    })
    .ReceiveJson();

Any help on getting that data nested similar to the Ruby example?


Solution

  • check this

    var x = new
    {
        type = "workorder.generated",
        data = new[]{ new {
            id= 1,
            type= "orders"
          },new {
            id= 2,
            type= "orders"
          },new {
            id= 3,
            type= "orders"
          }
        }
    }