RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
39.95k stars 10.3k forks source link

Files.IM API calls not pulling appropriate data #24172

Open wwc-trevor opened 2 years ago

wwc-trevor commented 2 years ago

Description:

When using curl to query the files.im api endpoint by roomId it states it cannot find the roomId. The roomID entered is the one listed in the MongoDB collection rocketchat_uploads.

When I query by username it states it is successful but list no files.

Steps to reproduce:

  1. Open command line or curl utility
  2. Type in curl command: curl -H "X-Auth-Token: MyGeneratedAuthTokenForAdminUser" -H "X-User-Id: 62izDxKnF3Zt4JJh5" https://RocketChat.OrgDomain.com/api/v1/im.files?roomId=LHtgHWbLqEx3pcYmMg4kLKTgDih7FvZDvg[^1]
  3. Receive error stating room cannot be found.
  4. Type in curl command to search by username: curl.exe -H "X-Auth-Token: MyGeneratedAuthTokenForAdminUser" -H "X-User-Id: 62izDxKnF3Zt4JJh5" https://rocketchat.wallawallaclinic.com/api/v1/im.files?username=trevor.moses[^1]
  5. Receive success message but with no files.

Expected behavior:

Return with data as shown in official rocketchat documentation using the room id (rid) listed in in rocketchat_uploads collection.

Actual behavior:

When querying by RoomId I get: {"success":false,"error":"The required \"roomId\" or \"username\" param provided does not match any direct message [error-room-not-found]","errorType":"error-room-not-found"}

I am getting the roomId (rid) from the MongoDB collection rocketchat_uploads. The RocketChat Server logs shown that it cannot find the room.

When querying by username I get results but they are empty. curl -H "X-Auth-Token: MyGeneratedAuthTokenForAdminUser" -H "X-User-Id: 62izDxKnF3Zt4JJh5" https://RocketChat.OrgDomain.com/api/v1/im.files?roomId=LHtgHWbLqEx3pcYmMg4kLKTgDih7FvZDvg

{"files":[],"count":0,"offset":0,"total":0,"success":true}

Server Setup Information:

Client Setup Information

Additional context

Relevant logs:

Query by RoomID Rocketchat Server Log {"level":35,"time":"2022-01-12T19:13:35.419Z","pid":27204,"hostname":"rocketchat","name":"API","method":"GET","url":"/api/v1/channels.files?roomId=LHtgHWbLqEx3pcYmMg4kLKTgDih7FvZDvg","userId":"62izDxKnF3Zt4JJh5","userAgent":"Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.1320","host":"rocketchat.OrgDomain.com","remoteIP":"192.168.52.68","err":{"type":"errorClass","message":"The required \"roomId\" or \"roomName\" param provided does not match any channel [error-room-not-found]","stack":"Error: The required \"roomId\" or \"roomName\" param provided does not match any channel [error-room-not-found]
at findChannelByIdOrName (app/api/server/v1/channels.js:32:9)
at Object.get (app/api/server/v1/channels.js:281:22)
at app/api/server/api.js:407:96
at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
at Object._internalRouteActionHandler [as action] (app/api/server/api.js:407:39)
at Route.share.Route.Route._callEndpoint (packages/nimble_restivus/lib/route.coffee:150:32)
at packages/nimble_restivus/lib/route.coffee:59:33
at packages/simple_json-routes.js:98:9","isClientSafe":true,"error":"error-room-not-found","reason":"The required \"roomId\" or \"roomName\" param provided does not match any channel","errorType":"Meteor.Error"},"status":400,"responseTime":3,"msg":"The required \"roomId\" or \"roomName\" param provided does not match any channel [error-room-not-found]"}
Query by Username Rocketchat Server Log {"level":35,"time":"2022-01-12T19:28:47.532Z","pid":27204,"hostname":"rocketchat","name":"API","method":"GET","url":"/api/v1/im.files?username=john.smith","userId":"62izDxKnF3Zt4JJh5","userAgent":"Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.1320","host":"rocketchat.OrgDomain.com","remoteIP":"192.168.52.68","status":200,"responseTime":13} {"level":35,"time":"2022-01-12T19:28:47.533Z","pid":27204,"hostname":"rocketchat","name":"API","method":"GET","url":"/api/v1/im.files?username=john.smith","userId":"62izDxKnF3Zt4JJh5","userAgent":"Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.1320","host":"rocketchat.OrgDomain.com","remoteIP":"192.168.52.68","status":200,"responseTime":17}

Screenshot

Screenshot_Bug

[^1]: Actual auth token not share for security purposes.

Jaiharishan commented 2 years ago

I will work on this issue.

sohamparate commented 2 years ago

Hey @wwc-trevor , I am not able to reproduce the error. Both roomId and username params give the expected results. Also, I think that it retrieves files from direct messages only as mentioned in the docs

wwc-trevor commented 2 years ago

@sohamp19 I am trying to extract the files uploaded in direct messages between users. I can spend time and go step by step. but a overview is:

  1. Look in _rocketchatuploads collection in MongoDB to find desired files and take the rid

image

NOTE Room is a direct message room (type: d):

image

  1. Go and make my curl call.

    curl.exe -H "X-Auth-Token: MySecureUserToken" -H "X-User-Id: 62izDxKnF3Zt4JJh5" https://RocketChat.wallawallaclinic.com/api/v1/im.files?roomId=LHtgHWbLqEx3pcYmMzXnpAxYRoAZ4LjX6R

    image

  2. Get error message (see photo above).

{"success":false,"error":"The required \"roomId\" or \"username\" param provided does not match any direct message [error-room-not-found]","errorType":"error-room-not-found"}
  1. Look in Rocketchat server logs.
RocketChat Server Logs ``` I20220119-21:08:37.960(0) UserPresence:online { id: 'sFGqEqEHFc9auMPJJ', clientAddress: '192.168.52.68', httpHeaders: { 'x-forwarded-for': '192.168.52.68', 'x-real-ip': '192.168.52.68', 'x-forwarded-proto': 'https', host: 'rocketchat.wallawallaclinic.com', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62', 'accept-language': 'en-US,en;q=0.9' }, userId: '62izDxKnF3Zt4JJh5' } {"level":35,"time":"2022-01-19T21:08:37.961Z","pid":384080,"hostname":"rocketchat","name":"Meteor","method":"UserPresence:online","userId":"62izDxKnF3Zt4JJh5","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62","remoteIP":"192.168.52.68","instanceId":"wrRZaafQmfcL5ctaX"} {"level":35,"time":"2022-01-19T21:08:47.263Z","pid":384080,"hostname":"rocketchat","name":"API","method":"GET","url":"/api/v1/im.files?roomId=LHtgHWbLqEx3pcYmMzXnpAxYRoAZ4LjX6R","userId":"62izDxKnF3Zt4JJh5","userAgent":"curl/7.79.1","host":"RocketChat.wallawallaclinic.com","remoteIP":"192.168.52.68","err":{"type":"errorClass","message":"The required \"roomId\" or \"username\" param provided does not match any direct message [error-room-not-found]","stack":"Error: The required \"roomId\" or \"username\" param provided does not match any direct message [error-room-not-found]
at findDirectMessageRoom (app/api/server/v1/im.js:26:9)
at Object.get (app/api/server/v1/im.js:139:22)
at app/api/server/api.js:407:96
at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
at Object._internalRouteActionHandler (app/api/server/api.js:407:39)
at app/api/server/api.js:407:96
at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
at Object._internalRouteActionHandler [as action] (app/api/server/api.js:407:39)
at Route.share.Route.Route._callEndpoint (packages/nimble_restivus/lib/route.coffee:150:32)
at packages/nimble_restivus/lib/route.coffee:59:33
at packages/simple_json-routes.js:98:9","isClientSafe":true,"error":"error-room-not-found","reason":"The required \"roomId\" or \"username\" param provided does not match any direct message","errorType":"Meteor.Error"},"status":400,"responseTime":6,"msg":"The required \"roomId\" or \"username\" param provided does not match any direct message [error-room-not-found]"} {"level":35,"time":"2022-01-19T21:08:47.268Z","pid":384080,"hostname":"rocketchat","name":"API","method":"GET","url":"/api/v1/im.files?roomId=LHtgHWbLqEx3pcYmMzXnpAxYRoAZ4LjX6R","userId":"62izDxKnF3Zt4JJh5","userAgent":"curl/7.79.1","host":"RocketChat.wallawallaclinic.com","remoteIP":"192.168.52.68","status":400,"responseTime":14} {"level":35,"time":"2022-01-19T21:08:48.401Z","pid":384080,"hostname":"rocketchat","name":"API","method":"POST","url":"/api/v1/method.call/license%3AgetModules","userId":"62izDxKnF3Zt4JJh5","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62","length":"96","host":"rocketchat.wallawallaclinic.com","referer":"https://rocketchat.wallawallaclinic.com/admin/view-logs","remoteIP":"192.168.52.68","status":200,"responseTime":1} ```

If I am doing something incorrect I cannot tell. You let me know

sohamparate commented 2 years ago

@wwc-trevor I am still not able to reproduce it.

Here is what I tried.

  1. Took the rid from rocketchat_uploads collection (Image below).

    image
  2. Verified that the type of room is 'd' (Image below).

    image
  3. Make a curl request to /api/v1/im.files endpoint curl -H "X-Auth-Token: MyAuthToken" -H "X-User-Id: dKePxY9xWMDAtrqqS" http://localhost:3000/api/v1/im.files\?roomId\=dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk

  4. Result:

{
  "files": [
    {
      "_id": "4p8pqkSnEHWeh8Xyw",
      "name": "gcp_quest1.jpeg",
      "size": 40592,
      "type": "image/jpeg",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "dKePxY9xWMDAtrqqS",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "jpeg",
        "size": {
          "width": 1280,
          "height": 243
        }
      },
      "complete": true,
      "etag": "zCAM4DmmnvYZa4yiK",
      "path": "/ufs/GridFS:Uploads/4p8pqkSnEHWeh8Xyw/gcp_quest1.jpeg",
      "progress": 1,
      "token": "980908db58",
      "uploadedAt": "2022-01-19T20:15:32.582Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/4p8pqkSnEHWeh8Xyw/gcp_quest1.jpeg",
      "_updatedAt": "2022-01-19T20:15:32.588Z",
      "typeGroup": "image",
      "user": {
        "_id": "dKePxY9xWMDAtrqqS",
        "username": "soham.parate",
        "name": "Soham Parate"
      }
    },
    {
      "_id": "2rbhQqpaCeFKdN5oa",
      "name": "gojo-chibi.jpg",
      "size": 25153,
      "type": "image/jpeg",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "dKePxY9xWMDAtrqqS",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "jpeg",
        "size": {
          "width": 600,
          "height": 600
        }
      },
      "complete": true,
      "etag": "KcyYCZtnmA85Pjksj",
      "path": "/ufs/GridFS:Uploads/2rbhQqpaCeFKdN5oa/gojo-chibi.jpg",
      "progress": 1,
      "token": "4B0959fbCa",
      "uploadedAt": "2022-01-19T19:45:48.259Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/2rbhQqpaCeFKdN5oa/gojo-chibi.jpg",
      "_updatedAt": "2022-01-19T19:45:48.265Z",
      "description": "gojo-chibi",
      "typeGroup": "image",
      "user": {
        "_id": "dKePxY9xWMDAtrqqS",
        "username": "soham.parate",
        "name": "Soham Parate"
      }
    },
    {
      "_id": "E4koes2tvX9DjLapQ",
      "name": "kitten.png",
      "size": 132907,
      "type": "image/png",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "dKePxY9xWMDAtrqqS",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "png",
        "size": {
          "width": 384,
          "height": 251
        }
      },
      "complete": true,
      "etag": "tHC8Y8t4w3kiki2XD",
      "path": "/ufs/GridFS:Uploads/E4koes2tvX9DjLapQ/kitten.png",
      "progress": 1,
      "token": "7b595bbbFA",
      "uploadedAt": "2022-01-19T20:12:40.964Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/E4koes2tvX9DjLapQ/kitten.png",
      "_updatedAt": "2022-01-19T20:12:40.971Z",
      "typeGroup": "image",
      "user": {
        "_id": "dKePxY9xWMDAtrqqS",
        "username": "soham.parate",
        "name": "Soham Parate"
      }
    },
    {
      "_id": "tm8it6dooFQbFv2du",
      "name": "pfp1compressed.jpeg",
      "size": 155602,
      "type": "image/jpeg",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "hedAszv5dMHfFjsbk",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "jpeg",
        "size": {
          "width": 1599,
          "height": 1066
        }
      },
      "complete": true,
      "etag": "MNjYGywzjn3B8TM35",
      "path": "/ufs/GridFS:Uploads/tm8it6dooFQbFv2du/pfp1compressed.jpeg",
      "progress": 1,
      "token": "2aF998491b",
      "uploadedAt": "2022-01-19T20:18:55.260Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/tm8it6dooFQbFv2du/pfp1compressed.jpeg",
      "_updatedAt": "2022-01-19T20:18:55.265Z",
      "typeGroup": "image",
      "user": {
        "_id": "hedAszv5dMHfFjsbk",
        "username": "soham-test",
        "name": "soham-test"
      }
    },
    {
      "_id": "EniRF6Bv6XRDQrRFz",
      "name": "thumb-gcp_quest1.jpeg",
      "size": 6479,
      "type": "image/jpeg",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "dKePxY9xWMDAtrqqS",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "jpeg",
        "size": {
          "width": 480,
          "height": 91
        }
      },
      "complete": true,
      "etag": "HNNQsiYxbyWQFyiwM",
      "path": "/ufs/GridFS:Uploads/EniRF6Bv6XRDQrRFz/thumb-gcp_quest1.jpeg",
      "progress": 1,
      "token": "a90A495a89",
      "uploadedAt": "2022-01-19T20:15:32.618Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/EniRF6Bv6XRDQrRFz/thumb-gcp_quest1.jpeg",
      "user": {
        "_id": "dKePxY9xWMDAtrqqS",
        "username": "soham.parate",
        "name": "Soham Parate"
      }
    },
    {
      "_id": "Jp9rmq7z3fcDa9v95",
      "name": "thumb-gojo-chibi.jpg",
      "size": 11981,
      "type": "image/jpeg",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "dKePxY9xWMDAtrqqS",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "jpeg",
        "size": {
          "width": 360,
          "height": 360
        }
      },
      "complete": true,
      "etag": "6cBBBH25hjJjf7kBM",
      "path": "/ufs/GridFS:Uploads/Jp9rmq7z3fcDa9v95/thumb-gojo-chibi.jpg",
      "progress": 1,
      "token": "6a0acb4938",
      "uploadedAt": "2022-01-19T19:45:48.302Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/Jp9rmq7z3fcDa9v95/thumb-gojo-chibi.jpg",
      "user": {
        "_id": "dKePxY9xWMDAtrqqS",
        "username": "soham.parate",
        "name": "Soham Parate"
      }
    },
    {
      "_id": "FyZoZePkCndrGN4H7",
      "name": "thumb-pfp1compressed.jpeg",
      "size": 31738,
      "type": "image/jpeg",
      "rid": "dKePxY9xWMDAtrqqShedAszv5dMHfFjsbk",
      "userId": "hedAszv5dMHfFjsbk",
      "store": "GridFS:Uploads",
      "identify": {
        "format": "jpeg",
        "size": {
          "width": 480,
          "height": 320
        }
      },
      "complete": true,
      "etag": "XvQv6sErdqRDt2MoX",
      "path": "/ufs/GridFS:Uploads/FyZoZePkCndrGN4H7/thumb-pfp1compressed.jpeg",
      "progress": 1,
      "token": "1a086A2BD9",
      "uploadedAt": "2022-01-19T20:18:55.329Z",
      "uploading": false,
      "url": "http://localhost:3000/ufs/GridFS:Uploads/FyZoZePkCndrGN4H7/thumb-pfp1compressed.jpeg",
      "user": {
        "_id": "hedAszv5dMHfFjsbk",
        "username": "soham-test",
        "name": "soham-test"
      }
    }
  ],
  "count": 7,
  "offset": 0,
  "total": 7,
  "success": true
}

And I am using Rocket.Chat 4.4.0-develop. I just noticed :) Maybe this is fixed in newer versions

wwc-trevor commented 2 years ago

And I am using Rocket.Chat 4.4.0-develop. I just noticed :) Maybe this is fixed in newer versions

I hope so. Almost all the other API calls I have made have been successful but this one. DO you know when 4.4 is going to be released? I saw 4.3.2 is the latest.

sohamparate commented 2 years ago

@wwc-trevor no idea sir

wwc-trevor commented 2 years ago

Do you think it could be something with my reverse proxy?

Nginx Reverse Proxy Setup ``` # Upstreams upstream backend { server 127.0.0.1:3000; } # HTTPS Server server { listen 443 ssl; server_name rocketchat.wallawallaclinic.com; # You can increase the limit if your need to. client_max_body_size 200M; error_log /var/log/nginx/rocketchat.access.log; ssl_certificate /etc/nginx/certificate.crt; ssl_certificate_key /etc/nginx/private.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE location / { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Nginx-Proxy true; proxy_redirect off; } } #Redirect http traffic server { listen 80; server_name rocketchat.wallawallaclinic.com; return 301 https://$host$request_uri; } ```
Gua00va commented 1 year ago

Hey!! I want to work on this issue. I'm new here so I'm really excited to start contributing.

SyedAbuBakerAli commented 1 year ago

Hi, @wwc-trevor , can you assign me this issue

lokesh-wagh commented 11 months ago

Hey @wwc-trevor I think @sohamparate is right This endpoint seems to be working fine according to the documentation

It is displaying the file's sent in direct message's image

here i sent a file named apply_proxy

smitjiwani commented 8 months ago

@ggazzo , On reproducing this error i have found that the api is working as shown in the documentation

{
  "files": [
    {
      "_id": "657a9bccd111bca61b353acd",
      "name": "codecell proposal (1).pdf",
      "size": 33986,
      "type": "application/pdf",
      "rid": "65796859d315d66597ec1c7d",
      "userId": "EwgzmJMJsWecQcSxz",
      "store": "GridFS:Uploads",
      "_updatedAt": "2023-12-14T06:08:12.677Z",
      "complete": true,
      "etag": "Z4TtgxnfpGAfRzRts",
      "path": "/ufs/GridFS:Uploads/657a9bccd111bca61b353acd/codecell%20proposal%20(1).pdf",
      "progress": 1,
      "token": "2AD889EBF8",
      "uploadedAt": "2023-12-14T06:08:12.672Z",
      "uploading": false,
      "url": "https://3000-rocketchat-rocketchat-1z832tjp3fk.ws-us106.gitpod.io/ufs/GridFS:Uploads/657a9bccd111bca61b353acd/codecell%20proposal%20(1).pdf",
      "description": "ekrjafdnkjwds\\",
      "typeGroup": "application",
      "user": {
        "_id": "EwgzmJMJsWecQcSxz",
        "name": "smit",
        "username": "smitty"
      }
    }
  ],
  "count": 1,
  "offset": 0,
  "total": 1,
  "success": true
}
Asrani-Aman commented 8 months ago

@wwc-trevor is this issue is still open?

salmanzego commented 7 months ago

@Asrani-Aman I think the issue is solved since the endpoint is giving the expected response

Sibam-Paul commented 1 month ago

Please close this issue if this issue is solved

VanshikaSabharwal commented 2 weeks ago

If this issue is open .please assign it to me . @wwc-trevor