apigee / apigee-api-catalog-drupal

Manage your API catalog within Drupal's content management approach
https://www.drupal.org/project/apigee_api_catalog
GNU General Public License v2.0
17 stars 16 forks source link

Create API Doc - HTTP 422 error - spec.0.target_id: This entity (file: 72) cannot be referenced. #52

Closed nagashreeb closed 3 years ago

nagashreeb commented 5 years ago

Drupal8 Devportal.postman_collection.json.txt

I am trying to upload API specs and create API doc using the REST APIs of API catalog module on Apigee kickstart drupal8 devportal. While trying to Create the API doc with the file uuid from the upload spec response, I am seeing a HTTP 422 Unprocessable entity error. The Spec file upload works and I am also able to see the uploaded file content in the drupal content/files folder. I am trying option B provided in the documentation below. https://www.drupal.org/docs/8/modules/apigee-api-catalog/expose-rest-apis-to-interact-with-api-docs#s-create-api-docs

Attaching the postman scripts with request response payloads captured in the examples.

To Reproduce Steps to reproduce the behavior:

  1. Invoke the Create spec API - http://****.com/jsonapi/apidoc/apidoc/spec with a valid yaml file and appropriate credentials in the Authorization header.
  2. Scroll through the response and copy the id listed under file-file element "type": "file--file", "id": "d5ce836a-4805-4d61-a52d-374ebcf89673",
  3. Invoke the Create API doc API http://****.com/jsonapi/apidoc/apidoc with payload containing the API doc name, paste the file id from step 2 in the id attribute under spec/data, example below: "spec": { "data": { "type": "file--file", "id": "d5ce836a-4805-4d61-a52d-374ebcf89673" } }
  4. Scroll down to the response received, you will observe HTTP 422 with error detail "title": "Unprocessable Entity", "status": "422", "detail": "spec.0.target_id: This entity (file: 72) cannot be referenced.",

Expected behavior The API doc should be created and mapped to the uploaded spec file.

Screenshots If applicable, add screenshots to help explain your problem. image

Additional context

Version Info

arunz6161 commented 5 years ago

Hi @nagashreeb - I was unable to reproduce the issue locally. Could you specify the Drupal core version and API Catalog version that you are running ? If sharing your postman collection is an option then, i can open a support ticket to request that securely or you can email that to us.

nagashreeb commented 5 years ago

Hi @nagashreeb - I was unable to reproduce the issue locally. Could you specify the Drupal core version and API Catalog version that you are running ? If sharing your postman collection is an option then, i can open a support ticket to request that securely or you can email that to us.

Hi Arun, Below are the software versions used: Drupal version: 8.7.8 PHP: 7.3.9 Apigee API catalog: version: '8.x-1.0'

I also tried using the maven smartdocs plugin which internally uses these REST APIs, I didn't have any success with that as well. From the maven plugin it throws a HTTP 415 (issue logged https://github.com/apigee/apigee-smartdocs-maven-plugin/issues/13 ) I had a discussion with Sai Saran as well, and he suggested to raise the issue here.

I have attached the postman collection with my ticket as a .txt file. I can send it over email too if you can let me know the email id to send it to.

arunz6161 commented 5 years ago

@nagashreeb thanks. I upgraded Drupal core to: 8.7.8 and downgraded API catalog to version: '8.x-1.0'. Used the postman collection you shared but again had no luck reproducing the issue. Have you been able to import the spec and get it to display via the UI ? also are there any errors on the status page ?

nagashreeb commented 5 years ago

@nagashreeb thanks. I upgraded Drupal core to: 8.7.8 and downgraded API catalog to version: '8.x-1.0'. Used the postman collection you shared but again had no luck reproducing the issue. Have you been able to import the spec and get it to display via the UI ? also are there any errors on the status page ? Hi @arunz6161, - Yes, I am able to manually upload the spec yaml file and view it through the UI. I am also able to upload the spec file using the REST API -http://****.com/jsonapi/apidoc/apidoc/spec I see a HTTP 201 response with the JSON payload containing the file uuid. I see an issue with Create Spec - POST http://****.com/jsonapi/apidoc/apidoc only. manually-imported-spec

Another strange thing that Sai and myself noticed, When I run the smartdocs maven plugin, the commandline output shows Spec imported successfully with a uuid. If I use the uuid from the maven commandline output in the POST payload of the REST API in postman for http://****.com/jsonapi/apidoc/apidoc, it works and I see a HTTP 201 created response and i can also view the spec on the UI. However, if i use the file uuid received in the response of the REST API call http://****.com/jsonapi/apidoc/apidoc/spec from Postman I see this HTTP 422 issue. Does this help? A screenshot of the above described behaviour is attached here - spec-upload-with-fileid-from-maven-output

arunz6161 commented 5 years ago

@nagashreeb are you using the same user for your calls through Postman and with the Maven plugin?

nagashreeb commented 5 years ago

@nagashreeb are you using the same user for your calls through Postman and with the Maven plugin?

@arunz6161 - I have used the same user - apidocadmin in both Postman and Maven plugins. I have also tried with the admin user apigeeadmin, i see the same errors.

nagashreeb commented 4 years ago

@arunz6161 - any update on this issue?

cnovak commented 3 years ago

We are going to close this issue since it is very old, and seems to be an issue with JSON API core module, not this module. This module is using the Drupal core JSON API module to allow REST API calls. It may be https://www.drupal.org/project/jsonapi/issues/3032904 or related, if this is still an issue you should put a bug into Drupal.org for this.