Search code examples
jsonazure-form-recognizer

API call to analyze a custom form


I am trying to make an API call to Microsoft's form recognizer to analyze a form against a custom model and I can't figure out how to do it.

Here is the documentation on the API

https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api/operations/AnalyzeWithCustomModel

The request body is blank and I don't really know how that ought to be formatted in order to be sent off.

If you look at the POST Train model method, I was able to use that request body to send make that api call work. This indicates that the problem is me and not the API.

I have successfully done this with curl through command line...

curl -X POST "https://formrecognizerbp.cognitiveservices.azure.com/formrecognizer/v1.0-preview/custom/models/[MODEL ID]/analyze" -H "Content-Type: multipart/form-data" -F "form=@\"C:\Temp\Capture1.jpg\";type=image/jpeg" -H "Ocp-Apim-Subscription-Key: [SUBSCRIPTION ID]"

I don't really know/can't figure out how to convert that into a request body similar in format to what the POST Train Model method has.

I keep getting this error because I don't know how to format the request properly.

Internal : Unexpected error Error during Web API HTTP Request HTTP Status Code: 400 HTTP Response Content: {"value":{"error":{"code":"BadRequest","message":"Could not process incoming request: 'Missing content-type boundary.'. Please ensure that it is well-formed."}},"formatters":[],"contentTypes":[],"statusCode":400}

So I guess formatters and contentTypes are the missing pieces but would that just be the file path and the image/jpeg parts of the curl ?


Solution

  • The issue was that I did not realize that the curl script was overwritting the multipart/form-data Content-Type with image/jpeg and when I was trying to build out this call differently I was forcing a multipart/form-data Content-Type on what was a jpeg.