Error with Update part of a collection Postman API

I am trying to use Update part of a collection API to bulk update Authorization methods for all the collections in my workspace.

As per the Postman API Documentation, there is an example for Update part of a collection with the name Update Auth to update the authorization of a collection using the collection ID. The request body in the example is as follows:

curl --location --request PATCH 'https://api.getpostman.com/collections/12ece9e1-2abf-4edc-8e34-de66e74114d2' \
--data '{
    "collection": {
        "auth": {
            "type": "apikey",
            "apikey": [
                {
                    "key": "value",
                    "value": "PMAK-XXX",
                    "type": "string"
                },
                {
                    "key": "key",
                    "value": "api-key",
                    "type": "string"
                }
            ]
        }
    }
}'

I tried to implement the same for one of my collections using the following request body:

curl --location --request PATCH 'https://api.getpostman.com/collections/eb54b82c-9ea6-499a-98a1-499a22c7dcae' \
--header 'x-api-key: PMAK-6712**********a0696b4a4a4d' \
--header 'Content-Type: application/json' \
--data-raw '{
    "collection": {
        "auth": {
            "type": "apikey",
            "apikey": [
                {
                    "key": "in",
                    "value": "header",
                    "type": "string"
                },
                {
                    "key": "key",
                    "value": "authorizations",
                    "type": "string"
                },
                {
                    "key": "value",
                    "value": "Bearer 2~f8******mZGJiMg==",
                    "type": "string"
                }
            ]
        }
    }
}'

But I ended up with the following error message in response.

{
    "error": {
        "name": "badRequest",
        "message": "Invalid parameters: ('type') for key: 'collection.auth.apikey'"
    }
}

Please let me know if the Postman API request to update Auth part of a collection has been updated. Or if there is something wrong with the request I am trying to make.

1 Like

Hey @ramkumarps91 :wave:t2:

Does that request work if you remove the first object, with the in property? That’s not part of the example.

Hi @danny-dainton , I still get the same error message upon removing the first object

1 Like

Thanks for checking - could you try one more thing, please?

Can you remove the type property from the objects and give that a go?

I removed type but still get the same error

Are you able to show an example of that request?

We’ve tested that locally and that’s returning a 200 with the type removed. :thinking:

 {
     "collection": {
         "auth": {
             "type": "apikey",
             "apikey": [
                 {
                     "key": "value",
                     "value": "PMAK-XXX"
                 },
                 {
                     "key": "key",
                     "value": "api-key"
                 },
                 {
                     "key": "in",
                     "value": "header"
                 }
             ]
         }
     }
 }

I’ve attached a screenshot of the request and response with type removed

You have the type property in all those objects :thinking:

This should still remain "type": "apikey" but the ones in the objects, within the apikey array should remain. As per this example:

{
     "collection": {
         "auth": {
             "type": "apikey",
             "apikey": [
                 {
                     "key": "value",
                     "value": "PMAK-XXX"
                 },
                 {
                     "key": "key",
                     "value": "api-key"
                 },
                 {
                     "key": "in",
                     "value": "header"
                 }
             ]
         }
     }
 }

Oh Ok. Sorry, I understood it wrong. Yes, its working now :smiley: Thank you!!

Just one more question:

So this API is updating the Authorization tab of the requested collection but it is populating the value section with the actual value of the variable like Bearer 2~4d485** that is passed.

I would like the collection to be updated with just the variable {{loginAccessToken}}

Is there a way to to do this through some escape characters in the Postman Update API?? I have updated a screenshot below if it helps

Actual Output in the Authorization Tab

Expected Output in the Authorization Tab

Wouldn’t just adding it like this do that?

{
    "key": "value",
    "value": "{{loginAccessToken}}"
}

It would only place the value of the string in that field, it wouldn’t automatically change that to the variable value. :thinking:


It also looks like you’re using an older version of Postman, as the variables wouldn’t look like that now.

This is the version I am currently using. Should I update it to a more recent one?

I also tried in Postman 11.17.1 but ended up with the same result. In Authorization tab, variable value is updated in the Value section instead of the variable name. Attaching screenshot of the Postman version details

I’m at a disadvantage as I cannot see what you have in front of you or the request that you made.

If you used that PATCH request with a value like this:

{
    "key": "value",
    "value": "{{loginAccessToken}}"
}

If you have something different, you’ve sent something different as the payload or you’re not updating the Collection that you’re looking at.

It will not automatically render the hardcoded value, it will add the string value in your payload.

Let me apply the same steps to a new collection and give you a detailed breakdown on all the steps.

Productivity Collection (Authorization Tab) before API trigger

URL
PATCH https://api.getpostman.com/collections/{{Productivity_Workspace_ID}}

Request Payload

{
    "collection": {
        "auth": {
            "type": "apikey",
            "apikey": [
                {
                    "key": "in",
                    "value": "header"
                },
                {
                    "key": "key",
                    "value": "authorizations"
                },
                {
                    "key": "value",
                    "value": "{{loginAccessToken}}"
                }
            ]
        }
    }
}

Response

{
    "collection": {
        "id": "65abed89-2d36-4a6e-b4d5-1a65a613bbcf",
        "name": "Productivity",
        "description": null
    }
}

Productivity Collection (Authorization Tab) after API trigger

Does the same happen if you use a dummy variable? Like {{my_variable}} in the payload?

You’re making those requests in the new version but viewing them in the older enterprise app, correct? In the v11 onwards version, you would see scripts as a menu heading and not Pre-request / Tests.

In terms of using the new Enterprise Application, you’re going to need to discuss that with your team and the admins who have distributed that version.

I am making the requests from the enterprise app only. But even if use the regular app with v11 version, I end up with the same result.

However, when I use a dummy variable, I am getting the desired output

API call

Authorization tab

I guess as a work around, I could just delete my existing variable thus making it dummy, bulk update the request to all my collections and re-enable the variable.

Thank you so much for working through all the issues with me! Appreciate it.

I stand corrected, after trying that process out again, it does resolve the variable value in the field - I don’t think that’s quite right so I’ll speak to the team about that.

Leave it with me.

1 Like

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