I have to submit this JSON exactly or it does not work. While I was able to create most of it with the help of another member I cannot find information on dealing with nulls. When it submits the null value it will not run through the api.
Here is the JSON I must create
    {
            "resourceType": "Bundle",
            "type": "message",
            "entry": [
            {
                            "resource": {
                                            "resourceType": "MessageHeader",
                                            "timestamp": "2016-12-29T08:00:00-07:00",
                                            "id": "Test1",
                                            "event":
                                                            { "code": "diagnosticreport-provide" },
                                            "source":
                                                            { "endpoint": "http://yourdomain.com/api" },
                                            "destination": [
                                                            { "endpoint": "https://api.com/api/$process-message" }
                                            ]
                            }
            },
            {
                            "resource": {
                                            "resourceType" : "DiagnosticReport",
                                            "extension" : [{
                                                            "url" : "DiagnosticReportDefinition",
                                                            "extension" : [
                                                                            { "url" : "useNewMedications", "valueBoolean": "false" },
                                                                            { "url" : "providePDFReport", "valueBoolean": "false" },
                                                                            { "url" : "returnDetectedIssues", "valueBoolean": "true" },
                                                                            { "url" : "returnObservations", "valueBoolean": "true" },
                                                                            { "url" : "returnMedications", "valueBoolean": "true" },
                                                                            { "url" : "returnDosingGuidance", "valueBoolean": "true" },
                                                                            { "url" : "includePIMTable", "valueBoolean": "true" },
                                                                            { "url" : "includeDDIData", "valueBoolean": "false" },
                                                                            { "url" : "reportId", "valueString": "" }
                                                            ]
                                            }]
                            }              
            },
            {
                            "resource":{ 
                                            "resourceType": "ProcedureRequest", 
                                            "id": "17" 
                            }
            }]
}
Here is the code where I tried to do it and came close but having problems with nulls and one comma between the resources
        using System;
using Newtonsoft.Json;
public class Program
{
    public static void Main()
    {
        var obj = new RootReq()
        {resourceType = "Bundle", type = "message", entry = new Entry[]{new Entry()
        {resource = new Resource()
        {resourceType = "MessageHeader", timestamp = DateTime.Now, id = "Test1", _event = new Event()
        {code = "diagnosticreport-provide"}, source = new Source()
        {endpoint = "http://yourdomain.com/api"}, destination = new Destination[]{new Destination()
        {endpoint = "https://api.pgxportal.com/api/$process-message"}}}}, new Entry()
        {resource = new Resource()
        {resourceType = "DiagnosticReport", extension = new Extension[]{new Extension()
        {url = "DiagnosticReportDefinition", extension = new Extension1[]{new Extension1()
        {url = "useNewMedications", valueBoolean = "false"}, new Extension1()
        {url = "providePDFReport", valueBoolean = "false"}, new Extension1()
        {url = "returnDetectedIssues", valueBoolean = "true"}, new Extension1()
        {url = "returnObservations", valueBoolean = "true"}, new Extension1()
        {url = "returnMedications", valueBoolean = "true"}, new Extension1()
        {url = "returnDosingGuidance", valueBoolean = "true"}, new Extension1()
        {url = "includePIMTable", valueBoolean = "true"}, new Extension1()
        {url = "includeDDIData", valueBoolean = "false"}, new Extension1()
        {url = "reportId", valueString = ""}, }}}}}, new Entry()
        {resource = new Resource()
        {resourceType = "ProcedureRequest", id = "17"}}}};
        var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
        Console.WriteLine(str);
    }
}
public class RootReq
{
    public string resourceType
    {
        get;
        set;
    }
    public string type
    {
        get;
        set;
    }
    public Entry[] entry
    {
        get;
        set;
    }
}
public class Entry
{
    public Resource resource
    {
        get;
        set;
    }
}
public class Resource
{
    public string resourceType
    {
        get;
        set;
    }
    public DateTime timestamp
    {
        get;
        set;
    }
    public string id
    {
        get;
        set;
    }
    public Event _event
    {
        get;
        set;
    }
    public Source source
    {
        get;
        set;
    }
    public Destination[] destination
    {
        get;
        set;
    }
    public Extension[] extension
    {
        get;
        set;
    }
}
public class Event
{
    public string code
    {
        get;
        set;
    }
}
public class Source
{
    public string endpoint
    {
        get;
        set;
    }
}
public class Destination
{
    public string endpoint
    {
        get;
        set;
    }
}
public class Extension
{
    public string url
    {
        get;
        set;
    }
    public Extension1[] extension
    {
        get;
        set;
    }
}
public class Extension1
{
    public string url
    {
        get;
        set;
    }
    public string valueBoolean
    {
        get;
        set;
    }
    public string valueString
    {
        get;
        set;
    }
}
Here it what the wrong json that this code is producing looks like
      {
  "resourceType": "Bundle",
  "type": "message",
  "entry": [
    {
      "resource": {
        "resourceType": "MessageHeader",
        "timestamp": "2017-05-24T06:45:36.0632742+00:00",
        "id": "Test1",
        "_event": {
          "code": "diagnosticreport-provide"
        },
        "source": {
          "endpoint": "http://yourdomain.com/api"
        },
        "destination": [
          {
            "endpoint": "https://api.pgxportal.com/api/$process-message"
          }
        ],
        "extension": null
      }
    },
    {
      "resource": {
        "resourceType": "DiagnosticReport",
        "timestamp": "0001-01-01T00:00:00",
        "id": null,
        "_event": null,
        "source": null,
        "destination": null,
        "extension": [
          {
            "url": "DiagnosticReportDefinition",
            "extension": [
              {
                "url": "useNewMedications",
                "valueBoolean": "false",
                "valueString": null
              },
              {
                "url": "providePDFReport",
                "valueBoolean": "false",
                "valueString": null
              },
              {
                "url": "returnDetectedIssues",
                "valueBoolean": "true",
                "valueString": null
              },
              {
                "url": "returnObservations",
                "valueBoolean": "true",
                "valueString": null
              },
              {
                "url": "returnMedications",
                "valueBoolean": "true",
                "valueString": null
              },
              {
                "url": "returnDosingGuidance",
                "valueBoolean": "true",
                "valueString": null
              },
              {
                "url": "includePIMTable",
                "valueBoolean": "true",
                "valueString": null
              },
              {
                "url": "includeDDIData",
                "valueBoolean": "false",
                "valueString": null
              },
              {
                "url": "reportId",
                "valueBoolean": null,
                "valueString": ""
              }
            ]
          }
        ]
      }
    },
    {
      "resource": {
        "resourceType": "ProcedureRequest",
        "timestamp": "0001-01-01T00:00:00",
        "id": "17",
        "_event": null,
        "source": null,
        "destination": null,
        "extension": null
      }
    }
  ]
}
 
    