API call to analyze a custom form - json

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 ?

The /trainCustomModel API expects the data to be present on the Azure Blob storage. The request body to this request needs to contain a valid SAS URL to the training data. Once you successfully create a custom trained model ID, you could use that to analyze the forms. The /AnalyzeWithCustomModel API expects the data to be on your local file storage. Please ensure that you have the replaced the ModelId, API Subscription Key (Note this is not the same as subscription ID) and the local path to the image correctly.

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.

Related

Is there a way to get a propertiesUrl from Autodesk Forge's Model Properties API that is not pre-signed?

I am writing a Dynamo script to extract the properties out of all of the models in my modelset in BIM 360. Some of the files (notably the ones with more objects) will give me a pre-signed propertiesUrl value that looks like this:
https://bim360-nucleus-production-us-east-1-temporary-index.s3.amazonaws.com/36174d28-fbd6-4146-a3af-3f3a7bb8ec52/index/v2/indexes/5JAa5g6Nk-t5KQsgFe5OJA/properties.ldjson.gz?X-Amz-Expires=60&X-Amz-Security-Token={{token_value}}-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential={{Credential_value}}/20220509/us-east-1/s3/aws4_request&X-Amz-Date=20220509T223945Z&X-Amz-SignedHeaders=host&X-Amz-Signature={{Amz_Signature_Value}}
This pre-signed URL has been troublesome because it will expire within 60 seconds of being issued and Dynamo is having trouble making the requests on time, or because I will get a network transport error when using the DynaWeb package (only 1/3 requests are made successfully):
Dynaweb Network Transport Error
When I try using Dynamo's OOTB node "Web Request", it will give me values that contain characters that aren't even close to what the response should be.
Dynamo Web Request OOTB Response
Is there a way to circumvent the need for a pre-signed url for the "propertiesUrl" endpoint? I can't find anything in the API in how to download the properties from the indices besides what is detailed here (which shows how to get properties with a Bearer token, but not how to opt out of a pre-signed url format):
https://forge.autodesk.com/en/docs/acc/v1/reference/http/index-v2-index-properties-get/
curl -v 'https://developer.api.autodesk.com/construction/index/v2/projects/cd743656-f130-48bd-96e6-948175313637/indexes/da39a3ee5e6b4b0d/properties' -H 'Authorization: Bearer <token>'

How to test rest API with large json

I am writing rest api with Flask. One of my endpoints handles a post request. One field of the request JSON 'audio' is supposed to contain the BASE64 encoded PCM file (audio format). If save this field to a file, it is about 200KB.
It might be too big to copy and paste in Swagger or Postman for testing. Even worse with curl command. Is there any good way to test with really big JSON in the request.
I'd recommend a great tool called Insomnia. You can send point it to any file to send it as a HTTP request. You can change the Content-Type header to be application/json and select your JSON data file. Here's a screenshot of what the program looks like.

How to use a GET curl in postman?

I have this curl example:
curl -i -X GET -H "Content-Type:application/json" https://dev.ga.coach/intervention/:getworse/ -d '{"user_id": "012ab3", "section_id": "6"}'
When I run it through cygwin it's working properly! When I'm trying to import it in postman then it shows it as POST and I get the following response.
<h1>Not Found</h1>
<p>The requested URL /intervention/ was not found on this server.</p>
When I test https://dev.ga.coach/intervention/:getworse/ through web browser, this is what I see:
cURL allows you to include a payload on a GET request but the HTTP specification says:
A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.
When you try to make the same request with Postman, you are experiencing it "rejecting" the request. In this case, the rejection comes in the form of it converting to a POST request instead.
It would be appropriate to include a JSON payload on a POST request, but since it looks like you are trying to GET information you should move the data to the URL instead.
For example:
https://dev.ga.coach/intervention/012ab3/6/:getworse/
This will require you change your server-side code (which you, presumably, can do since you said I'm developing the rest-apis) to read the data from the new location.

Pentaho HTTP Post multipart/form-data

I am trying to use HTTP Post to post the data by passing following Header and Body part,
Body:
One image URL having file path. Type as 'File'
Metadata in JSON format. Type as 'Text'
Headers:
Content-type = multipart/form-data
Authorization = Bearer 5412
Here is the screenshot of complete request,
This is how I have setup the HTTP Post task in Pentaho,
I found related post here using REST Client but this also didn't help: Pentaho HTTP Post using JSON
Really appreciate your help.
I think the problem is that "Post a file" doesn't mean include a file in the request, but rather to get the entire request from that file.
I don't know the specifics of how the data should look in the Post request, but the rough approach should be:
Pass the filename field to a Calculator step with the operation "Load file content to binary" to get a binary type field (ex: myimage)
Base64 (or other) encode the data with a Javascript step like this:
var encString = new Packages.java.lang.String( Packages.org.apache.commons.codec.binary.Base64.encodeBase64( myimage ) );
Wrap it in some content-type string indicating the encoding
Include the field in your request.
There is a patch on https://jira.pentaho.com/browse/PDI-14743 to enable proper binary transfer instead of String when using Rest Client.

When use AWS Lambda to process mails from mailgun, can't get mails in JSON format

What I am tried to do is to have a lambda function proccess emails forwarded by mailgun.
So far, I have setup mailgun's route so it will forward emails to a AWS api gateway, then the api gateway triggers a lambda function.
The problem comes when I try to process the mail, instead of getting a pretty Json that I am expecting inside the lambda's event.body, I m getting raw post form data like
--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Content-Type\"\r\n\r\nmultipart/mixed; boundary=\"001a1140216cee404d05440c49e7\"\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Date\"\r\n\r\nTue, 20 Dec 2016 13:40:53 +1300\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent ......
My question is, what should I do to get the JSON version of the forwarded emails in lambda?
Not sure if you ever came to a solution, but I have this working with the following settings.
Setup your API Gateway method to use "Use Lambda Proxy integration"
In your lambda (I use node.js) use busboy to work through the multi-part submission from mailgun. (use this post for help with busboy Busboy help)
Make sure that any code you are going to execute after all busboy is complete is executed in the 'finish' portion of the busboy code.
This suggests that your mailgun route is misconfigured and ends with a MIME request:
When you specify a URL of your application as a route destination through a forward() action, Mailgun will perform an HTTP POST request into it using one of two following formats:
Fully parsed: Mailgun will parse the message, transcode it into UTF-8 encoding, process attachments, and attempt to separate quoted parts from the actual message. This is the preferred option.
Raw MIME: message is posted as-is. In this case you are responsible for parsing MIME. To receive raw MIME messages, the destination URL must end with mime
From Receiving Messages via HTTP through a forward() action