iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
600 stars 210 forks source link

issues with iTwin and iModel get endpoints #5164

Closed habdirad closed 11 months ago

habdirad commented 1 year ago

Describe the bug Get My iTwins endpoint does not return all (Synchro) projects on our account (only returns a small fraction of them) - I have account admin permissions: https://developer.bentley.com/apis/itwins/operations/get-my-itwins/

We have been using https://developer.bentley.com/apis/projects/operations/my-projects, which worked properly and returned several hundred projects (we use similar $top parameter so the request limit is not at issue) but this endpoint is being deprecated and has caused another issue as described below.

Also, we cannot get iModels from many projects anymore with our app: https://developer.bentley.com/apis/imodels-v2/operations/get-itwin-imodels/

when we use iTwinId as a url parameter, we get the following error:

422 Unprocessable Entity
content_length: 186
content_type: application/json
request_context: appId=cid-v1:caffab81-b80a-40d1-a9e3-3d1a07228483
x_correlation_id: a089c4ee-654d-4290-bd38-6a670279a9c6
x_itwinplatform_media_type: bentley.itwin-platform.v1
x_itwinplatform_region: East US
date: Fri, 03 Mar 2023 06:14:02 GMT

{
  "error": {
    "code": "InvalidiModelsRequest",
    "message": "Cannot get iModels.",
    "details": [
      {
        "code": "MissingRequiredParameter",
        "message": "Required parameter is missing.",
        "target": "projectId"
      }
    ]
  }

when we use projectId as a url parameter, we get the following error:

500 Internal Server Error
content_length: 111
content_type: application/json
x_correlation_id: 4893d0da-8b25-4d13-bd40-19a5536dfd4e
request_context: appId=cid-v1:caffab81-b80a-40d1-a9e3-3d1a07228483
x_itwinplatform_media_type: bentley.itwin-platform.v1
x_itwinplatform_region: East US
date: Fri, 03 Mar 2023 06:12:24 GMT

{
  "statusCode": 500,
  "message": "Internal server error",
  "activityId": "d2690d6c-339f-43c9-8ba7-d1b0fecb0fec"
}

The tryout webapp on documentation works fine, but our webapp with all scopes enabled returns the errors above.

To Reproduce Call the endpoints with our app and our account.

https://api.bentley.com/itwins/?subClass=Project

https://api.bentley.com/imodels/?iTwinId=XXXXXXXX

Expected behavior Return all Synchro projects as iTwins. Return iModels when requested using projectId or iTwinId.

austeja-bentley commented 1 year ago

Hello, could you please specify how are you consuming iModels API - via the @itwin/imodels-client-management NPM package or calling it directly?

If you are using the mentioned API package, version 3.0.0 of that package targets iModels API V2 and should form a correct request. Please let me know if that is not the case.

If you are calling the iModels API directly, please note that we strongly recommend to always explicitly specify the API version that you intend to target using accept header. This is how you target iModels API V2 - documentation. If you explicitly target iModels API V2 you should be able to use ?iTwinId={someId} url query parameter. If you do not specify the API version explicitly the request goes to the default version (which is V1) and there it complains about missing projectId parameter. Please add the suggested accept: application/vnd.bentley.itwin-platform.v2+json header and let me know if the issue persists.

davidhjones commented 1 year ago

Hi @habdirad -- as you have noticed, the iTwins API (https://developer.bentley.com/apis/itwins/operations/get-my-itwins/) only returns the iTwins for which you are a member of (https://developer.bentley.com/apis/access-control/operations/get-itwin-members/).

If I understand correctly, since you personally are an Account Administrator, you would expect the get-my-itwins API to return all iTwins. I'd like to better understand that requirement. How are you utilizing this API call? Is it for some type of reporting? Have you built an interface on top of this API to visualize all iTwins in your Account? If you can, I'd like to learn more so I have a better context as to why you expect this API to work as you said.

habdirad commented 1 year ago

Hello, could you please specify how are you consuming iModels API - via the @itwin/imodels-client-management NPM package or calling it directly?

If you are using the mentioned API package, version 3.0.0 of that package targets iModels API V2 and should form a correct request. Please let me know if that is not the case.

If you are calling the iModels API directly, please note that we strongly recommend to always explicitly specify the API version that you intend to target using accept header. This is how you target iModels API V2 - documentation. If you explicitly target iModels API V2 you should be able to use ?iTwinId={someId} url query parameter. If you do not specify the API version explicitly the request goes to the default version (which is V1) and there it complains about missing projectId parameter. Please add the suggested accept: application/vnd.bentley.itwin-platform.v2+json header and let me know if the issue persists.

Thank you for the directions that helped fixing the issue with iModels. I added the header as suggested ("Accept" : "application/vnd.bentley.itwin-platform.v2+json") and passed my project Ids into the iTwinId parameter.

habdirad commented 1 year ago

Hi @habdirad -- as you have noticed, the iTwins API (https://developer.bentley.com/apis/itwins/operations/get-my-itwins/) only returns the iTwins for which you are a member of (https://developer.bentley.com/apis/access-control/operations/get-itwin-members/).

If I understand correctly, since you personally are an Account Administrator, you would expect the get-my-itwins API to return all iTwins. I'd like to better understand that requirement. How are you utilizing this API call? Is it for some type of reporting? Have you built an interface on top of this API to visualize all iTwins in your Account? If you can, I'd like to learn more so I have a better context as to why you expect this API to work as you said.

Thank you for your reply. Yes, this is for reporting purposes. As an account admin, I want to ensure our projects are setup correctly (e.g., they have the right naming convention, report job numbers, and have iModels set up as expected).

I may be using a scheduled flow (e.g., workato, powerautomate, or a basic webapp) to extract data. So there is no user interface. Jsons are stored in a container to be consumed by reports (e.g., PowerBI).

So ideally, I should not need to invite myself to all projects in order to get data of all iTwins in our account.

habdirad commented 1 year ago

Hi @davidhjones, please take a look at the previous comment and let me know if it makes sense to have an account level view of projects (without being invited to all projects). Thank you.

davidhjones commented 1 year ago

Hi @habdirad, sorry for the delayed response. You can choose to query all of your Organization's iTwins (if you are an organization admin) by adding this header:

X-iTwin-Query-Scope=OrganizationAdmin

FWIW, by default, this header (if missing) is set to X-iTwin-Query-Scope=MemberOfiTwin, where only the iTwins you are a member of are within the query scope.

aruniverse commented 1 year ago

@habdirad can this issue be closed or are you still running into some issues?

ben-polinsky commented 11 months ago

@habdirad Please reach out if the issue is not fixed.

habdirad commented 11 months ago

The issues are fixed. Thank you all for the guidance.