Textract API restFul ? Which Parameters ?


Is the textract service usable via Rest API?

If so what are the exact parameters to provide on the REST request?

And what are the exact parameters to provide in the elaboration of the canonical request.

For my part I tried the following code:

request_HTTP is restRequest

request_HTTP..URL = URLEncode("https://textract.eu-west-3.amazonaws.com")

request_HTTP..Method = httpPost

request_HTTP.ContentType = "application/x-amz-json-1.1"

request_HTTP.Content = { "Document": { "Bytes":"xxxxx" } } xxxx is the binary buffer of a file = Hash(NameFile.jpg)

requete_HTTP..Header["authorization"] = AWS4-HMAC-SHA256 Credential=myAWSAccessKey/20220411/eu-west-3/textract/aws4_request,SignedHeaders=content-type;host;x-amz-date,Signature=55fbb067c5ea5612146f7252b341fa22473338b6703cf1ad6703cf1

request_HTTP..Header["x-amz-algorithm"] = "AWS4-HMAC-SHA256"

request_HTTP..Header["x-amz-credential"] =myAWSAccessKey/20220411T093952Z/eu-west-3/textract/aws4_request

request_HTTP..Header["x-amz-date"] = "20220411T093952Z"

requete_HTTP..Header["x-amz-target"] = "Text.AnalyzeExpense"

for the canonical request allowing to create the chain to be signed the following code:

POST\n/\nAction=AnalyzeExpense\ncontent-Type:application/x-amz-json-1.1; charset=utf-8\nhost:textract.amazonaws.com\nx-amz-date:20220411T122110Z\ncontent-type;host;x-amz-date\nbufHash_RequestPayload

or bufHash_RequestPayload=LowerCase(Hex(Hash NameFile.jpg))= 14a085e370add4de92a3509c7891c27c9373b37b5ba83c3e395a8570303658c3

In the end I have the answer: "__type":"InvalidSignatureException", "message":"The request signature we calculated does not match the signature you provided

I certainly forgot something in advance thank you for your help

nb: x-amzn-RequestId: 7877cc30-b196-40dd-8e3d-ba6c9dcf6200

demandé il y a 2 ans1534 vues
1 réponse


The easiest way to consume the APIs is through the SDKs (for instance in python : https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/textract.html)

But if you need to implement the REST calls on your own, you can look at the API documentation here : https://docs.aws.amazon.com/textract/latest/dg/API_Operations.html

Here is the reference to create the Sigv4 canonical request: https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html

répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions