Log in or register to post comments

VWS TargetNameExist Updating Problem

February 26, 2016 - 8:24am #1

Hi there,

We have a situation where we have a large amount of markers on a cloud database that each have a unique name (a SKU ID that relates to a product in a store). Every week we add/remove/update these markers in modest quantities (around 20-30) per week.

To make this process easier, we use the VWS to batch upload the new markers. At the moment though we haven't been able to figure out how to update our markers using VWS.

We want our code to do this:

- Attempt to upload marker

- If marker already exists (TargetNameExist result), find out which marker

- Switch to an update request instead and replace the marker with the same name

The trouble is we can't figure out the target_id of the marker that is already on the cloud. The result just returns the result code and a transaction ID. If we can't get the target_id then we can't use the update API.

Is there a way to get the target_id of the marker when you receive a "TargetNameExist" result, or is there a way to get a marker by it's name and not the target_id?

VWS TargetNameExist Updating Problem

March 1, 2016 - 4:32pm #9

Ah ok. Looks like the dictionary file list will be a temporary solution for now. Thanks for your help and for forwarding on to the product improvement team, hopefully it would be possible to include the infringing target_id when you receive a name conflict error.

VWS TargetNameExist Updating Problem

March 1, 2016 - 4:10pm #8

Sorry, that was my misunderstanding about the update command requiring the target id. You are correct, you can't update an existing target without the target id. In this case, the workaround for that would be to request all the target ids in the DB (using /targets) and then call Target Summary Report (/summary/{target_id}) for each of them to associate the ids to the names.

https://developer.vuforia.com/library/articles/Solution/How-To-Get-a-Target-List-for-a-Cloud-Database-Using-the-VWS-API

We have made note of this use-case issue to share with our product improvement team.

 

VWS TargetNameExist Updating Problem

March 1, 2016 - 3:14pm #7

Really sorry but we just don't seem to be understanding each other, though I appreciate the help and detail you've provided so far. I understand the process of creating the associateive array that you've described, what I don't understand is the part afterwards where I do the actual update to the affected targets.

In your post, you say at the end "look through the associateive array for any targets that don't have a target_id associated to them". So here in your solution, we don't have a target_id to use.

Now when after that you say "re-upload the affected targets using update", this is the bit I want to focus on.

We look at the documentation that you linked to (How to Update a Target Using the VWS API), it says I have to post using https://vws.vuforia.com/targets/{target_id}

To re-upload the affected targets using update, I need to know the target_id of the thing I want to replace, but how do I get that target_id in your solution? As you point out in your solution, when the first upload fails, I don't get a target_id back. All I seem to have is the target_id of the successful uploads, which aren't of use.

VWS TargetNameExist Updating Problem

March 1, 2016 - 2:53pm #6

For the case of 3 existing targets on DB:

target1
target2
target3

And 3 additional targets to upload:

target4
target2 (already exists in DB)
target5

Your batch upload only needs awareness of 4, 2, and 5. When using posting target4, a successful response JSON will include the new target id:

{
    "result_code":"TargetCreated",
    "transaction_id":"ca3cade977...",
    "target_id":"784b2eaa04..."
}

You should then confirm the name associated to target "784b2eaa04...", by calling the Target Summary Report "/summary/[target_id]" which will include the target_name in its JSON response:

{
    ...
    "target_name":"target4",
    ...
}

Then in an associative array object in memory, store the target_name and its target_id (i.e. JSON format):

{
    "target4":"784b2eaa04..."
    "target2":
    "target5":
}

When you attempt to upload target2 which already exists, you'll get an error JSON:

{
    "result_code":"TargetNameExist",
    "transaction_id":"e79a2d02d2..."
}

You can have a variable named targetNameExistErrCount and assign it the number of errors it finds (i.e. 0, 1, 2...). Increment this for each instance of that error.

When the script has finished attempting to upload all 3 targets, look through the associative array for any targets that don't have a target_id associated to them. For the number of items without a target_id, compare it to the variable targetNameExistErrCount to confirm that the quantity matches and then re-upload the affected targets using update.

Reference these APIs:

https://developer.vuforia.com/library/articles/Solution/How-to-Add-a-Target-Using-VWS-API

https://developer.vuforia.com/library/articles/Solution/How-To-Retrieve-a-Target-Summary-Report-using-the-VWS-API

https://developer.vuforia.com/library/articles/Solution/How-To-Update-a-Target-Using-the-VWS-API
 

VWS TargetNameExist Updating Problem

March 1, 2016 - 1:57pm #5

Right ok sorry, I'm not sure if I'm being stupid but I'm still not seeing how it can work without a dictionary file of all markers on the database. It might be the way I'm explaining things so I'll try to come up with a more detailed example:

Say on my cloud database I have three targets named target1, target2 and target3.

There's a new batch of products I have to process, including a new image of target2 that has the latest product branding. In my batch uploader, I currently have no way of telling what the target_id (the 32 character ID) of each of those three targets on the cloud are unless I build a complete key/pair file beforehand (which isn't ideal in my scenario).

I go to upload the new content for the week. target4 and target5 go up fine, but the new image for target2 is rejected due to the TargetNameExist result code. It's easy for me to tell which markers have been rejected, but what I'm struggling on is how I go about choosing to update those markers after the "post new" attempt has failed.

When I try to upload target2, I don't have access to the target_id of the target2 marker on the cloud. When my request is rejected, I don't receive any information about the marker on the cloud (the only information I get is the result code and transaction ID, should there be more?). From what I can see in the VWS documentation, the only way I can perform an update to target2 is by having the target_id of what I want to replace, but in this scenario my batch uploader hasn't received this information from anywhere.

When following your instructions I'm not really clear on how it allows me to update the targets afterwards, I can only see that it would tell me which markers failed to upload due to a target with the same name already existing. Without getting the target_id somewhere, I would still have to manually update each of the targets which is what I want to avoid. I'd like the process to be as fully automated as possible so we could scale up to coping with much bigger content updates.

I wouldn't say I'm very knowledgeable of the VWS, is there something I've missed that would allow me to use the VWS update request after a TargetNameExist failed upload?

VWS TargetNameExist Updating Problem

March 1, 2016 - 1:00pm #4

The workaround I detailed earlier has no dependency on a central file or persistent record keeping beyond the batch upload occurrence itself. If you have 3 targets you need to upload on a particular day you run through the steps keeping the returned values in an associative array object with their names and then do a post check at the end to see which targets already exist in the Cloud DB and need to be updated instead. Once the batch process finishes, no local records remain unless you want them to.

VWS TargetNameExist Updating Problem

March 1, 2016 - 6:51am #3

Hm, so essentially I'd have to maintain a file which contains a dictionary of target names against IDs.

I can't say I'm really a fan of that approach as our uploads can take place from different systems, and it would then become crucial that all systems have access to a version of that dictionary file that is up to date. We couldn't re-build the dictionary file every batch upload as that would take a long time (not to mention use an awful lot of API requests).

Thanks for the suggestion, it's a shame that there's no better way to do it. I might look into seeing whether we can host this dictionary file on a web server that can have read/write whenever there's a batch upload, it just seems a bit overkill for something so simple.

VWS TargetNameExist Updating Problem

February 26, 2016 - 5:19pm #2

You might try the following steps:

  1. Post a target
  2. If successful, save the "target_id" value and call the Target Summary report on that ID to retrieve and store the "target_name" with that record
  3. If post returns with an error, save the "result_code" to reference at end of batch upload
  4. When uploads complete, see which targets don't have an associated ID in your local records
  5. If the only errors that you've recorded are "TargetNameExist", then you will know which targets need to be updated

 

 

Log in or register to post comments