Closed Komal-99 closed 4 weeks ago
@Komal-99 have you looked at this guide here. https://docs.aws.amazon.com/solutions/latest/enhanced-document-understanding-on-aws/developer-guide.html#api-reference. Yes in this release the API schema has changed.
Yes , but here in API reference no Schema is provided.
Can you guide me?
So you can export the swagger or Open API spec if you have deployed the solution from the API Gateway web console. Here is the API Gateway documentation on how you can do it - https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html
Hi , Not able to resolve it till now, can you elaborate more, will exporting swagger gives me the JSON payload expected to pass to the API?
The Swagger will give you the JSON schema for the payload.
You can also capture the actual payload, if you have the solution deployed and while using the web inspector in browsers like chrome and firefox.
Hi @knihit , Thanks, I downloaded Swagger files and got an idea of the payload. However, we don't have a deployed solution as we need to use only the API integrated into our solution.
While I am trying the New payload from the Python script it shows 403 error: forbidden
on the Rest API request to create caseID Figure 1 and when calling it from postman it gives a CustomExecutionError: Cannot read properties of undefined (reading 'concat')
which on my research is same as Undefined because Case is not getting Creating. figure 2
looking for guidance and help :)
Hi @knihit @mukitmomin looking for an answers if you could help.
The format of the Authorization header is incorrect i believe. You do not need Bearer
, just the {"Authorization" : <token>}
should be fine. You can try using this function as a sample
# create a function to parse a command line argument for case name
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--case_name", help="Name of the case to be created", required=False, default=DEFAULT_CASE_NAME)
args = parser.parse_args()
return args
def create_case(case_name: str = None):
if not case_name:
case_name = DEFAULT_CASE_NAME
create_case_endpoint = f"{REST_API_ENDPOINT}/case"
headers = {"Authorization": token, "User-Agent": USER_AGENT, "Content-Type": "application/json"}
try:
response = requests.post(
create_case_endpoint, headers=headers, json={"caseName": case_name, "enableBackendUpload": False}
)
if response.status_code == 200:
return response.json()
except Exception as e:
raise e
if __name__ == "__main__":
args = parse_args()
response = create_case(args.case_name)
pprint(response)
I have tested that bit of code with the v2 release of EDU and it is working.
How to get an Authorization token? I am using a session token. Because I removed the Authorization from all the APIs by editing the API from API gateway.
The upload-document lambda function has a method to create cases. To ensure only valid users can create cases the Authorization jwt token is decoded to extract the cognito userId claim jwt token, using this function in the common-node-lib.
If you have removed the Authorization mechanism then you have to modify the logic for validating case creation, as implemented here. The error you are seeing is coming from this line because the userId in that function is undefined as you removed the Authorization mechanism.
Hi @mukitmomin @knihit , I am opening this issue to check if the Request body for RestAPI got updated. Not able to find it but my previous code throughs me an error of Invalid Request Body.
When Passing a String
case_id
due to which case not getting created and I am not able to use the service.Originally posted by @Komal-99 in https://github.com/aws-solutions/enhanced-document-understanding-on-aws/issues/31#issuecomment-2267525886