Tracking codes data type and manipulation

2019-03-05 23:59发布

Tracking codes allow an enterprise (such as us) to store some local ID in the users' data on Box. I realize that the functionality needs to be enabled on the enterprise (which our contacts are working on).

First question: The documentation says it's an "array", and other answers indicate that it's an array of "name/value pairs". In datatypes, what exactly does Box API consider to be a "name/value"-pair?

Is it a list of dictionaries with string keys and string values (and in that case - what happens if two of the dictionaries share keys), a list of strings with a "/" separator, or can I put any data type I like into the array?

Second question: do I manipulate the tracking_codes array like a normal attribute (i.e. do i PUT a new array to /2.0/users/USERID to update it), or do I manage it like other arrays (such as email aliases) by POST/DELETE to /2.0/users/USERID/tracking_codes?

Thank you.

标签: box-api
1条回答
干净又极端
2楼-- · 2019-03-06 00:31

Ok... No answers here, and none from Box support, so I experimented and contacted another enterprise whose working script I could use as a base.

  1. "tracking_codes" need to be enabled for the enteprise. The documentation does not mention this. If you don't enable tracking_codes, you get the standard and very unhelpful "invalid request parameters" error.

  2. The names of the specific tracking_codes you intend to use must be registered in the "enterprise settings" ("user settings" tab) of Box' administration pages. The documentation wrongly says that "any name/value pair" can be used, but only names that are pre-registered work. If you use a name that hasn't been registered, you get the unhelpful "invalid request parameters" error.

  3. To set a tracking_code, you update the list of tracking_codes as an attribute. The format of each name/value pair must be: {"type": "tracking_code", "name": "[a name you have registered]", "value": "[any string]"}. So for example, if you've registered "personid" as a valid tracking_code, you can PUT to /2.0/users/[userid] the body

    {"tracking_codes": [{"type": "tracking_code", "name": "personid", "value": "1318231313"}]}

  4. I have not found any way to remove a tracking_code once set. PUT:ing an empty list does nothing. The best possibility seems to be putting an empty string as value for the tracking code, but it is still returned of course.

查看更多
登录 后发表回答