09 October 2015

How to unarchive an Optimizely Goal

I recently ran into a problem with Optimizely where I could not unarchive a goal for a custom event. There was no way to change this from the website and I couldn’t create a new goal for the same custom event (since they are uniqued per event name).

There customer support confirmed it’s not in the site, but it is possible via their API (which turns out to have a nice Stripe-like format for documentation and examples). So, here’s a quick and dirty way to unarchive an Optimizely goal using their API and cURL for anyone else who encounters this problem.

1. Generate a token

Get one here: https://app.optimizely.com/tokens

It will look like: “abcdef1234567890abcdef1234567890:12345678”

2. List projects

$ curl \
  -H "Token: abcdef1234567890abcdef1234567890:12345678" \
  -X GET "https://www.optimizelyapis.com/experiment/v1/projects/"

[
  {
    "project_name": "My Web Project",
    "id": 12345,
    ...
  },
  ...
]

3. List goals for that project id

$ curl \
  -H "Token: abcdef1234567890abcdef1234567890:12345678" \
  -X GET "https://www.optimizelyapis.com/experiment/v1/projects/12345/goals/"

[
  {
    "archived": true, 
    "id": 98765, 
    "title": "Some Event", 
    "event": "someEvent", 
    ...
  }, 
  ...
]

4. Update that goal id

Note: PUT operates like you’d expect PATCH to work.

A PUT request updates an entity. The id for the entity to update is provided in the URL, and the new data is provided in the body as JSON. Only the data that you're changing needs to be provided. Missing fields will keep their original values.

$ curl \
  -H "Token: abcdef1234567890abcdef1234567890:12345678" \
  -H "Content-Type: application/json" \
  -d '{"archived":false}' \
  -X PUT "https://www.optimizelyapis.com/experiment/v1/goals/98765/"

{
  "event": "someEvent", 
  "archived": false,
  "id": 98765, 
  "title": "Some Event", 
  ...
}
comments powered by Disqus

Peter Coles

Peter Coles

is a software engineer who lives in NYC, works at Ringly, and blogs here.
More about Peter »

github · soundcloud · @lethys · rss

It’s time to get big money out of politics. Join the kick-started campaign to put government back in the hands of the people. Pledge mayday.us now