Cannot delete collection items via the Postman API

Ok this seems to be a recent change as Danny told me in earlier inquiries of mine that I need to add it otherwise I will see errors (which was true at the time).

When you say just for the /apis/ endpoints isn’t this an example of an api call?

https://api.getpostman.com/collections/11112000-bxxxd3xx-y1y2-54jk-1lkj-8af111288881/requests

this is an example endpoint where I added the x-api-key header and the one we’re discussing above

Yes, it is a recent change. Before, the v2 header was necessary for these endpoints, but now they are part of the regular Postman API.
The /apis endpoints are the https://api.getpostman.com/apis endpoints. Endpoints to manage your APIs via the Postman API (Postman). If you take a look at that documentation, you’ll see two folders in the collection: v9 and v10. The v10 header is necessary for the v10 endpoints.

Thank you I think I understand now, I got mixed up the /apis/ with https://api.getpostman.com/collections, thought I am calling the collections endpoint wrongly because of v2 v9 v10.

Thanks again for the time and explanation, have you got any comments with regards to the initial problem. I’ve provided the request bodies I am using for the collection examples, have you seen anything wrong with them etc.?

The collection in question is still in a really funky state, all changes I am doing on it keep adding more new requests and it’s a big mess. I am mostly surprised by calling PUT on the collection does not even clearing it up from all its items.

Are there postman logs available where I could see what’s going on under the hood when I try to delete something or when a request to the collection is made, presumably it fails but unsure why.

Thanks again for your time!

In the console log I am seeing the following

image

Unsure whether this is a problem at all?

loading the collection from incognito browser
image

how the collection looks on the postman desktop client (masked/deleted the names on the image)

if I click for the first image on create request, all items from the 2nd image appear from somewhere, and this is the only collection which behaves like this

if I call GET collections/collectionID
I get the following response

{
    "collection": {
        "info": {
            "_postman_id": "some-guid-id",
            "name": "some-name",
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
            "updatedAt": "2023-10-05T12:02:02.000Z",
            "uid": "some-uid"
        },
        "item": []
    }
}

if I export the collection from the desktop client I get a json with all the items that appear in the collection…
if I call a response example POST serverUrl/path/collectionItemName I get the expected response, but the Get collections/collectionID suggests my collection is empty… this is really confusing. I have deleted the mock server and mocked collection several times but the new ones behave exactly the same.

Thanks for reading my wall of text, hope it helps!

Hi, Cris!
I’ll read the whole thread and will come back to you tomorrow.

1 Like

Hi, Cris!
The main issues I see in the thread are:

  • You must use the PATCH endpoint to update the collection name, not the PUT endpoint. The PUT endpoint overwrites the whole collection. That’s probably why you lose the information.
  • You can manage the collection items (requests, responses, and folders) using the collection items API. You can fully CRUD these items (create, update, read, and delete them). Please see the examples we provide in the public postman collection here: Postman

I would advise working initially with a single request and creating a process that works with just that request. The collection items API works well if you follow the examples we provide in the public Postman collection. We provide examples to create requests and responses of many different types (GET, POST, with auth, with tests…), please check the body you are sending when you create the request is correct. Once you have that working collection, with a single request, add the rest of the requests, and it should work the same way.

Thanks!

Hi David @david-espi-hernandez ,

I am doing everything right, I promise! I got your point mixing up PATCH/PUT, I only reset the collection with PUT and do not make any updates with it. The actual problem is around that and deleting ghost collection items.

when I do a PUT with this body

{
    "collection": {
        "info": {
            "name": "test_collection",
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
        },
        "item": []
    }
}

Nothing changes, which is not our expectation?

Yesterday I tried to delete one directly with the api i.e.
https://api.getpostman.com/collections/collectionId/requests/requestId

and got this response

{
    "error": {
        "name": "forbiddenError",
        "message": "You are not permitted to perform the action.",
        "details": {
            "model": "request",
            "model_id": "some-guid",
            "owner": "12345678",
            "message": "You are not authorized to access this instance."
        }
    }
}

any ideas why I am not authorized to perform delete?

logs from the desktop app

[21388][1696581943647][requester][info]["RequestInterfaceV2~deleteRequest - Delete request failed: ",{"error":{"name":"instanceNotFoundError","message":"We could not find the request you are looking for","details":{"model":"request","model_id":"fa236d55-f286-f510-2e8d-8070f019cf8b","owner":"11111111"}},"status":404,"headers":{}}]
[21388][1696581943675][requester][error]["Error in pipeline for deleting request",{"name":"Error","message":"Error in deleting request: 11111111-fa236d55-f286-f510-2e8d-8070f019cf8b","stack":"Error: Error in deleting request: 11111111-fa236d55-f286-f510-2e8d-8070f019cf8b\n    at https://desktop.postman.com/_ar-assets/common-a195baebf2b28d18.min.js:10182:491102\n    at nrWrapper (https://desktop.postman.com/?desktopVersion=10.18.10&userId=11111111&teamId=540469:10:29518)"}]

it’s funny as I am deleting it manually and it’s there but it’s not there?

also doing get collection returns no items but I actually see them and can actually request them?!

a bulk delete attempt

[21388][1696582585450][requester][error]["CollectionSidebarModel~handleDelete: Delete call failed",{"name":"Error","message":"Failed to apply patches to collections","stack":"Error: Failed to apply patches to collections\n    at https://desktop.postman.com/_ar-assets/common-a195baebf2b28d18.min.js:10182:325054\n    at nrWrapper (https://desktop.postman.com/?desktopVersion=10.18.10&userId=11111111&teamId=540469:10:29518)"}]

also not sure what this means and whether it is important but there u go

[21388][1696582576035][requester][error]["ReleaseListStore~getReleases: apiId or apiVersionId is missing"]
[21388][1696582576127][requester][info]["AutosaveManager~subscribeToSettingsUpdates: Settings is initialised."]
[21388][1696582576442][requester][error]["CommentController~getCommentCount: Something went wrong while fetching comment count.",{"trace":"v=1;t=906950452c04b6e1","error":{"name":"unauthorized","message":"You do not have access to this resource","code":403}}]
[21388][1696582576442][requester][error]["CommentsContributor~fetchRequestCommentsCount: Failed to fetch comments count"]

Hi!
Can you provide me with a collection that I can import and execute locally to reproduce the error? It’s difficult for me to figure out what’s going on.
Thanks!

Hi @david-espi-hernandez,

Let me know if I should open a new thread. I will try to illustrate the problem again

  1. I create a postman mock server mocking a collection
  2. I create requests and example responses (programmatically by creating the request then using its id to create the example response, this happens in a foreach loop for all collection items I am creating ~15 in total)
  3. I then need to recrate all examples and responses
  4. I request a PUT to the collection
  5. I then create requests and example responses (programmatically by creating the request then using its id to create the example response, this happens in a foreach loop for all collection items I am creating ~15 in total)

What I am experiencing is that the postman client is showing me duplicates of the requests/responses. When I try to delete any or all I receive these errors

image
and
image

then I check the content of the collection with a GET and the response is emtpty

{
    "collection": {
        "info": {
            "_postman_id": "b53ed3ce-a5c7-43ad-9faa-8af055220261",
            "name": "collection",
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
            "updatedAt": "2023-10-09T11:17:22.000Z",
            "uid": "userId-collectionId"
        },
        "item": []
    }
}

but the postman client is still showing me all these duplicate requests which I cannot manually remove.

  1. Using the postman web-client I am getting the stale responses ids from the url (remember according to result of GET collection, the collection is empty)

  1. Calling Delete on https://api.getpostman.com/collections/cid/requests/rid now returns
{
    "model_id": "f7b0b560-7444-a49b-b731-b3d54737c86a",
    "meta": {
        "model": "request",
        "action": "destroy"
    },
    "data": {
        "id": "f7b0b560-7444-a49b-b731-b3d54737c86a",
        "owner": "15363406"
    },
    "revision": 33003106812
}
  1. Observing the collection with stale items, the deleted item is now gone, however, it’s really tedious to do this by hand just to clean up the collection.

Previously I was creating the whole collection with a PUT with all requests and responses as a single call, but hit the problem with postman mock payload of 1mb, and my collections have different sizes up to 15mbs and would probably grow more. So I resorted to create collection items one by one executing the correct api endpoints for that, but that appeared troublesome.

Questions to answer here would be

  1. why the desktop/web clients seem out of sync and somehow retain old request/example pairs?
  2. why PUT with empty collection does not seem to do what it is expected of it (at least not according to the web/desktop clients)
  3. why Delete request work when the API returns an empty collection

Hope this can help your attempt in reproducing this issue.

Thanks

EDIT: After I manually deleted all stale items, and programatically created them anew, calling GET on the collection still returns empty collection, when I can actually see all responses created in the web and desktop clients.

Note the desktop client shown compounded count of items (matching my attemts to create/recreate) I have found that using this option

image

helped syncronised the view between the web and desktop clients, however calling GET on the collection returns empty collection response via both clients.

calling GET on mockserverUrl/path/itemName
returns correctly the response

@danny-dainton @david-espi-hernandez I appreciate your help thus far, but the issue is still unresolved, anny suggestions on what we could do next to investigate and fix?

Thank you!

Hi, Cris!
I think the best option is to have a short meeting where you can show me what you do. Please try to find a slot in my calendar so we can talk: Calendly - David Espi Hernandez
In any case, if in step 4 you are doing a PUT, you probably want to do a PATCH instead.

Booked for Monday! Thanks!

1 Like

Hi! I’ve replied to this issue in the GitHub ticket here: Postman API and Postman Client out of sync · Issue #12350 · postmanlabs/postman-app-support · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.