title: Marketo - Response of Bulk API serialization
body: <p>I'm trying to use the Bulk Import API endpoint within Marketo to fetch the <a href="https://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Bulk_Import_Leads/getImportLeadWarningsUsingGET" rel="nofollow noreferrer">warnings</a> and <a href="https://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Bulk_Import_Leads/getImportLeadFailuresUsingGET" rel="nofollow noreferrer">failures</a> associated with a bulk job I <a href="https://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Bulk_Import_Leads/importLeadUsingPOST" rel="nofollow noreferrer">created</a> within Marketo.</p>
  <p>The output of these jobs is stated as an <code>ObservableOfInputStreamContent</code>, yet the response of these endpoints returns a csv string (with header column), that's not a JSON object. To compound to this problem, we are using the generated swagger files with the swagger definition file provided by <a href="https://developers.marketo.com/rest-api/endpoint-reference/download-swagger-definition/" rel="nofollow noreferrer">Marketo</a>. These generated c# client side files have the <code>ObservableOfInputStreamContent</code> object, but it's an empty object. I'm not sure if this is intended, or a mistake on Marketo's side. The generated files will attempt to use <code>Newtonsoft.Json.JsonConvert.DeserializeObject&lt;ObservableOfInputStreamContent&gt;(responseText, JsonSerializerSettings);</code> to deserialize the API response to the <code>ObservableOfInputStreamContent</code>.</p>
  <p>Generated code that deserializes the API response:</p>
  <pre><code>var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
  try
  {
      var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject&lt;T&gt;(responseText, JsonSerializerSettings);
      return new ObjectResponseResult&lt;T&gt;(typedBody, responseText);
  }
  catch (Newtonsoft.Json.JsonException exception)
  {
      var message = &quot;Could not deserialize the response body string as &quot; + typeof(T).FullName + &quot;.&quot;;
      throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
  }
  </code></pre>
  <p>Problem one is that the API does not return JSON to begin with (eg):</p>
  <pre><code>address,city,country,
  123 lane, new york, USA
  745 street, new york, USA
  </code></pre>
  <p>This call will return this error because of this:</p>
  <blockquote>
  <p>Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: a. Path '', line 0, position 0.</p>
  </blockquote>
  <p>The second issue is that  <code>ObservableOfInputStreamContent</code> is defined as an empty object to begin with in the generated files. So if the API response was valid JSON, I don't think it would know how to convert to that empty <code>ObservableOfInputStreamContent</code> object. The good news about the generated code is that it gives me an option to extend the <code>ObservableOfInputStreamContent</code> because it's defined as a <code>partial</code> class.</p>
  <pre><code>[System.CodeDom.Compiler.GeneratedCode(&quot;NJsonSchema&quot;, &quot;10.1.11.0 (Newtonsoft.Json v11.0.0.0)&quot;)]
  public partial class ObservableOfInputStreamContent
  {
  
  }
  </code></pre>
  <p>That said, is there any possible way I can use the <code>JsonSerializerSettings</code> to get around this issue? Could I extended the <code>ObservableOfInputStreamContent</code> class to hold a string property and then create my own <a href="https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm" rel="nofollow noreferrer">JsonConverter</a> to convert the string returned from the API into the new <code>ObservableOfInputStreamContent</code>?</p>