AWS Textract analyze expense REST API

0

I want to analyze invoice with REST API request in Postman. URL: https://textract.eu-west-2.amazonaws.com Method: POST Body:

{
   "Document": { 
      "Bytes": "iVBORw0KGgoAAAANSUhEUgAAAu4AAAQlCAMAAADePLi1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA+5pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj..."
}
}

Blob in body was shortened in this post, but it's generated base64 string of invoice image

Response: 404 Response body:

{
	"Output": {
		"__type": "com.amazon.coral.service#UnknownOperationException"
	},
	"Version": "1.0"
}

How to use it then? https://docs.aws.amazon.com/textract/latest/dg/API_AnalyzeExpense.html#API_AnalyzeExpense_RequestSyntax

Enter image description here Enter image description here

asked 2 years ago966 views
1 Answer
1

You pass in the request syntax JSON as the request. Also it is important to note that you will need to get an image/pdf file, and pass it through the payload of the request as a Byte array or S3 object - which what I see that you have done correctly. But you have to authenticate (sign it: https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html), that is the harder part. The response does not give the processed output, but only the JobID and status. To authenticate before you call, you need to setup your IAM user in postman using the following steps:

  1. Obtain the access key and secret key for the IAM user.
  2. Open Postman and create a new POST request.
  3. In the Authorization tab, select "AWS Signature" from the TYPE dropdown menu.
  4. In the Access Key field, enter the access key for the IAM user.
  5. In the Secret Key field, enter the secret key for the IAM user.
  6. In the AWS Region field, enter the region where you want to make the API call (e.g., "us-west-2").
  7. In the Service Name field, enter "textract".
  8. In the Request URI field, enter the appropriate endpoint for the AnalyzeExpense action.
  9. Add a JSON payload to the Body of the request with the necessary attributes and values to call the API
  10. Send the request

It is important to note that the AnalyzeExpense API is part of the Textract async operations, which means the first request will return a JobId and the actual results will be on a different endpoint, you will need to keep checking the Job Status endpoint with that jobId until it is complete.

I see you have the endpoint correctly picked as well. Here is the page that shows a full list of endpoints used for each service per region. Here is a direct link to textract specifically: https://docs.aws.amazon.com/general/latest/gr/textract.html The section https://docs.aws.amazon.com/textract/latest/dg/API_Operations.html describes the request and response structures for each of the APIs. Have you taken a look at this document - https://docs.aws.amazon.com/textract/latest/dg/API_Reference.html

profile pictureAWS
answered 2 years ago
  • Thanks for your reply. I guess that I'm authenticated because I try to analyse uploaded file to S3 storage that I uploaded with API and uploading was successful. I think that I've problem with 'AnalyseExpense' part in URL. I don't know how can I pass it to URL. I tried as key 'action' or 'actions' and value 'AnalyseExpense' but nothing works. I could not find any information about name of query param or value. So if this URL is not correct, which one is? https://textract.eu-west-2.amazonaws.com?action=AnalyzeExpense

  • If you gave me an example of correct API URL request for AnalyzeExepense, I would be happy cuz I'm still lost. Thanks

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions