Update tags on multiple image files hosted in Box

Hi All,

Looking to update the tags on multiple images I have uploaded to Box, having no issue using the GET List items in folder API in Postman but it’s taking the response so I can update the individual tags for each file and then POST back to Box that is causing me headaches - can anyone help? I have approx 2500 images to update the tags on so I’d rather not do it directly within Box if I can avoid it.

Please consider reading this:

I’ve done that, can’t find anything about updating multiple files on Box using Postman.

Hey @cjc7

I believe @vdespa was referring to the way the question has been structured and the need to expand on the details that you have provided to explain the problem.

I have my response from the GET List items in folder request saved as a json file, I am now trying to use the Update File API to update the tags on multiple image files rather than having to do it one-by-one.

Where I am struggling is under the Params tab, Key (file_id) Value pair as there is a bulk-edit option which I’m probably wrong in thinking will allow me to update multiple files at once, but I cannot figure out a way to get this to work.

The Bulk Edit option, in that context, will just give you a different method of adding/reordering/removing query params.

You mentioned using a json file - do you have the id’s of all the files you would like to update in the there?

Hi Danny,

Yes I have the response from the GET request saved as a json file, sample below:

{
	"type": "file",
	"id": "737772734477",
	"etag": "0",
	"tags": ["I want to update this tag"]
}, {
	"type": "file",
	"id": "737771963228",
	"etag": "0",
	"tags": ["This one too"]
}, {
	"type": "file",
	"id": "737773455188",
	"etag": "0",
	"tags": ["And this"]
}, {
	"type": "file",
	"id": "737770989622",
	"etag": "0",
	"tags": ["I'm jewish and so is my wife"]
}

You could use that file, the format might be different, to drive the updates and reference the values from that data file in the request.

What does the update request look like for you, the one that you’re currently doing 1 by 1?

This is where I am at, which works and updates a single file on Box:

What I thought I needed to do is loop over my response.json file and create a key with multiple values to use in the bulk editor such as the below but I can’t get it work :frowning:

{ "file_id": ["1", "12", "123"] }

If you had a data file like this:

[
	{
		"type": "file",
		"id": "737772734477",
		"etag": "0",
		"tags": [
			"I want to update this tag"
		]
	},
	{
		"type": "file",
		"id": "737771963228",
		"etag": "0",
		"tags": [
			"This one too"
		]
	},
	{
		"type": "file",
		"id": "737773455188",
		"etag": "0",
		"tags": [
			"And this"
		]
	},
	{
		"type": "file",
		"id": "737770989622",
		"etag": "0",
		"tags": [
			"I'm jewish and so is my wife"
		]
	}
]

You can reference those different objects as your request body using this in the pre-request

pm.variables.set("update_body", JSON.stringify(pm.iterationData.toObject()))

The add the {{update_body}} variable to the PUT request body:

Once you have that in place, save the request and open the Collection Runner. Select the collection and the datafile and hit the Run button.

Thanks Danny, have tried the above with a test.json file and this is what I get:

Is the route correct? Is the request saved in the Builder (no orange dot in the tab)?

I don’t know that API so I don’t know what’s happening here by those screenshots alone :smiley:

I believe so, have checked the content-type is correct too re: the API docs

You have a path variable (:file_id) that isn’t getting resolved to anything, that doesn’t seem right.

I’m guessing that you could just add {{id}} to the value and id should get picked up in the collection run, if you don’t have id saved in any other variable scope.

Just make sure you save any changes before using the runner. :smiley:

1 Like

That’s done the job! Thanks for your guidance Danny!

1 Like