Skip to content

Instantly share code, notes, and snippets.

@joelind
Last active August 29, 2015 14:20
Show Gist options
  • Save joelind/a9e6e94b421bfc2d1b41 to your computer and use it in GitHub Desktop.
Save joelind/a9e6e94b421bfc2d1b41 to your computer and use it in GitHub Desktop.
6 transactions to http://qa-api.ea.autodesk.com
POST /admin/v1/accounts HTTP/1.1
User-Agent: Faraday v0.9.1
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Content-Length: 478
Host: qa-api.ea.autodesk.com
category=paid&corporate_account_name=Account+3daeed5b-44e1-4110-83e5-a610176413f6&corporate_account_number=Account+3daeed5b-44e1-4110-83e5-a610176413f6&display_name=Account+3daeed5b-44e1-4110-83e5-a610176413f6&email=joe.lind%2Bc2e2c02f-11e2-4291-aa82-27b7741e70ae%40autodesk.com&end_date=2021-01-01&name=Account+3daeed5b-44e1-4110-83e5-a610176413f6&price_model=enterprise_unlimited&project_exports_enabled=true&service_types=field&start_date=2001-01-01&user_exports_enabled=true
HTTP/1.1 201 Created
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 06 May 2015 18:36:46 GMT
ETag: "ccca7a85ebca601a7aff1bb3f918d162"
Server: Apache
Status: 201 Created
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: Phusion Passenger 4.0.53
X-Request-Id: 0f931c1b-5dc4-4de8-adc1-d8b00763ed9e
X-Runtime: 0.224098
X-XSS-Protection: 1; mode=block
Content-Length: 878
Connection: Close
{"id":"6120dc1f-851a-4302-888e-e16f0ef38e24","name":"Account 3daeed5b-44e1-4110-83e5-a610176413f6","display_name":"Account 3daeed5b-44e1-4110-83e5-a610176413f6","category":"paid","price_model":"enterprise_unlimited","start_date":"2001-01-01T00:00:00.000Z","end_date":"2021-01-01T00:00:00.000Z","status":"active","status_reason":null,"max_projects":null,"project_exports_enabled":null,"max_users":null,"user_exports_enabled":null,"corporate_account_name":"Account 3daeed5b-44e1-4110-83e5-a610176413f6","corporate_account_number":"Account 3daeed5b-44e1-4110-83e5-a610176413f6","deprecated_image_url":null,"website_url":null,"created_at":"2015-05-06T18:36:46.642Z","updated_at":"2015-05-06T18:36:46.642Z","image_file_name":null,"image_content_type":null,"image_file_size":null,"image_updated_at":null,"processing_image_key":null,"company_id":"d4fe5667-378f-4a7c-bcbf-f1cf2ecec942"}
POST /admin/v1/accounts/6120dc1f-851a-4302-888e-e16f0ef38e24/projects HTTP/1.1
User-Agent: Faraday v0.9.1
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Content-Length: 102
Host: qa-api.ea.autodesk.com
end_date=2021-01-01T00%3A00%3A00%2B00%3A00&name=Project+A&start_date=2001-01-01T00%3A00%3A00%2B00%3A00
HTTP/1.1 201 Created
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 06 May 2015 18:36:46 GMT
ETag: "f9bbe69fabf474360a6b2524a07376eb"
Server: Apache
Status: 201 Created
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: Phusion Passenger 4.0.53
X-Request-Id: 7bbe7eac-5095-47c2-aa78-3cc67c2c331c
X-Runtime: 0.128583
X-XSS-Protection: 1; mode=block
Content-Length: 798
Connection: Close
{"id":"2a467e92-651b-4a19-9830-661359a190f7","account_id":"6120dc1f-851a-4302-888e-e16f0ef38e24","name":"Project A","start_date":"2001-01-01T00:00:00.000Z","end_date":"2021-01-01T00:00:00.000Z","value":null,"currency":null,"status":"inactive","total_member_size":0,"total_company_size":1,"deprecated_image_url":null,"job_number":null,"address_line_1":null,"address_line_2":null,"city":null,"state_or_province":null,"postal_code":null,"country":null,"business_unit_id":null,"work_location":null,"work_breakdown":null,"created_at":"2015-05-06T18:36:46.911Z","updated_at":"2015-05-06T18:36:46.977Z","project_type":null,"image_file_name":null,"image_content_type":null,"image_file_size":null,"image_updated_at":null,"processing_image_key":null,"timezone":null,"status_reason":"pending","language":null}
POST /admin/v1/accounts/6120dc1f-851a-4302-888e-e16f0ef38e24/projects HTTP/1.1
User-Agent: Faraday v0.9.1
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Content-Length: 102
Host: qa-api.ea.autodesk.com
end_date=2021-01-01T00%3A00%3A00%2B00%3A00&name=Project+B&start_date=2001-01-01T00%3A00%3A00%2B00%3A00
HTTP/1.1 201 Created
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 06 May 2015 18:36:47 GMT
ETag: "2d33d433a1a6736dcc4541f78cf5dbd4"
Server: Apache
Status: 201 Created
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: Phusion Passenger 4.0.53
X-Request-Id: d42411df-200e-4b68-9db3-f4874f1257ee
X-Runtime: 0.122273
X-XSS-Protection: 1; mode=block
Content-Length: 798
Connection: Close
{"id":"eac2fef4-4bea-44b9-9c20-2e905768478a","account_id":"6120dc1f-851a-4302-888e-e16f0ef38e24","name":"Project B","start_date":"2001-01-01T00:00:00.000Z","end_date":"2021-01-01T00:00:00.000Z","value":null,"currency":null,"status":"inactive","total_member_size":0,"total_company_size":1,"deprecated_image_url":null,"job_number":null,"address_line_1":null,"address_line_2":null,"city":null,"state_or_province":null,"postal_code":null,"country":null,"business_unit_id":null,"work_location":null,"work_breakdown":null,"created_at":"2015-05-06T18:36:47.096Z","updated_at":"2015-05-06T18:36:47.155Z","project_type":null,"image_file_name":null,"image_content_type":null,"image_file_size":null,"image_updated_at":null,"processing_image_key":null,"timezone":null,"status_reason":"pending","language":null}
POST /admin/v1/accounts/6120dc1f-851a-4302-888e-e16f0ef38e24/projects/2a467e92-651b-4a19-9830-661359a190f7/users HTTP/1.1
User-Agent: Faraday v0.9.1
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Content-Length: 135
Host: qa-api.ea.autodesk.com
company_id=d4fe5667-378f-4a7c-bcbf-f1cf2ecec942&email=joe.lind%2Bca6feaca-f04c-45d9-8e4d-a55a91f06b07%40autodesk.com&service_type=field
HTTP/1.1 201 Created
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 06 May 2015 18:36:47 GMT
ETag: "6eec436c8e939884ec4778e4e2cfa3b8"
Server: Apache
Status: 201 Created
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: Phusion Passenger 4.0.53
X-Request-Id: db7af375-a2db-40e2-9499-b7afb626849f
X-Runtime: 0.189124
X-XSS-Protection: 1; mode=block
Content-Length: 380
Connection: Close
{"id":"e682b660-bd87-46e1-93ec-0f7c2d6222b0","account_user_id":"9a10c5c4-4c3d-4f23-9bb9-d95f969a8ac5","project_company_id":"d7230926-f42a-4dd5-8270-ef7362337cc6","user_id":"b371c2c5-4928-4210-841b-d451d5bfa315","service_project_id":"a0d0b6bf-0055-44c8-b2ae-a8b11166a820","invite_id":null,"role":null,"created_at":"2015-05-06T18:36:47.345Z","updated_at":"2015-05-06T18:36:47.345Z"}
POST /admin/v1/accounts/6120dc1f-851a-4302-888e-e16f0ef38e24/projects/eac2fef4-4bea-44b9-9c20-2e905768478a/users HTTP/1.1
User-Agent: Faraday v0.9.1
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Content-Length: 135
Host: qa-api.ea.autodesk.com
company_id=d4fe5667-378f-4a7c-bcbf-f1cf2ecec942&email=joe.lind%2Bca6feaca-f04c-45d9-8e4d-a55a91f06b07%40autodesk.com&service_type=field
HTTP/1.1 201 Created
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 06 May 2015 18:36:47 GMT
ETag: "64b06f52bd0fdd7d7da874379f75c2af"
Server: Apache
Status: 201 Created
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: Phusion Passenger 4.0.53
X-Request-Id: 299b653e-18cb-42ed-a2a2-b4df3bc20b6d
X-Runtime: 0.161057
X-XSS-Protection: 1; mode=block
Content-Length: 380
Connection: Close
{"id":"22921ff1-3f5b-4e80-83c2-481f3774b993","account_user_id":"9a10c5c4-4c3d-4f23-9bb9-d95f969a8ac5","project_company_id":"98549b1f-4738-4380-88ce-36096314d032","user_id":"b371c2c5-4928-4210-841b-d451d5bfa315","service_project_id":"60610b3e-7e38-4e83-90f4-beea91b4427a","invite_id":null,"role":null,"created_at":"2015-05-06T18:36:47.572Z","updated_at":"2015-05-06T18:36:47.572Z"}
GET /admin/v1/accounts/6120dc1f-851a-4302-888e-e16f0ef38e24/users?limit=10&offset=0 HTTP/1.1
User-Agent: Faraday v0.9.1
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Host: qa-api.ea.autodesk.com
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 06 May 2015 18:36:47 GMT
ETag: "559639750f64e0ad36938aa58e245fb7"
Server: Apache
Status: 200 OK
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: Phusion Passenger 4.0.53
X-Request-Id: c470af31-91eb-41c8-8732-b703c1e4ebfe
X-Runtime: 0.027974
X-XSS-Protection: 1; mode=block
Content-Length: 1239
Connection: Close
[{"id":"b371c2c5-4928-4210-841b-d451d5bfa315","email":"[email protected]","name":"New Member","nickname":null,"first_name":"New","last_name":"Member","uid":null,"image_url":null,"last_sign_in":null,"role":"project_user","address_line_1":null,"address_line_2":null,"city":null,"postal_code":null,"state_or_province":null,"country":null,"phone":null,"company":null,"job_title":null,"industry":null,"about_me":null,"created_at":"2015-05-06 18:36:47.309353","updated_at":"2015-05-06 18:36:47.309353","status":"inactive","status_reason":"pending","company_id":null,"company_name":null},{"id":"eb4e83d9-0727-4a02-992b-4d397f62abc2","email":"[email protected]","name":"New Member","nickname":null,"first_name":"New","last_name":"Member","uid":null,"image_url":null,"last_sign_in":null,"role":"account_admin","address_line_1":null,"address_line_2":null,"city":null,"postal_code":null,"state_or_province":null,"country":null,"phone":null,"company":null,"job_title":null,"industry":null,"about_me":null,"created_at":"2015-05-06 18:36:46.731698","updated_at":"2015-05-06 18:36:46.731698","status":"inactive","status_reason":null,"company_id":null,"company_name":null}]
require "rubygems"
require "bundler"
Bundler.require
HqClient.configure do |config|
config.api_host_name = "http://qa-api.ea.autodesk.com"
config.api_url_base = "/admin/v1"
config.service_type = "field"
end
account_name = "Account #{SecureRandom.uuid}"
account_email = "joe.lind+#{SecureRandom.uuid}@autodesk.com"
email = "joe.lind+#{SecureRandom.uuid}@autodesk.com"
account = HqClient::Account.create(
attributes: {
name: account_name,
display_name: account_name,
category: "paid",
price_model: "enterprise_unlimited",
start_date: '2001-01-01',
end_date: '2021-01-01',
email: account_email,
project_exports_enabled: "true",
user_exports_enabled: "true",
service_types: "field",
corporate_account_name: account_name,
corporate_account_number: account_name
})
# Create 2 projects
project_a = HqClient::Project.create(
account_id: account.id,
attributes: {
name: "Project A",
start_date: account.start_date,
end_date: account.end_date
}
)
project_b = HqClient::Project.create(
account_id: account.id,
attributes: {
name: "Project B",
start_date: account.start_date,
end_date: account.end_date
}
)
# Invite a user by email address to 2 different projects.
#
# NOTE: HQ provides no documented way for a client to specify an of invite ID when we create these invitations, and they returns an `invitation_id` that is null
invited_user = HqClient::ProjectUser.create(
account_id: account.id,
project_id: project_a.id,
company_id: account.company_id,
email: email,
attributes: {}
)
invited_user_2 = HqClient::ProjectUser.create(
account_id: account.id,
project_id: project_b.id,
company_id: account.company_id,
email: email,
attributes: {}
)
# Issue 1: How can we remove one of these invited users from a project? The API only allows us to remove a user by Oxygen ID. Need a mechanism to do this.
# Issue 2: What happens if some other service posts a signup with this same email address. Will HQ post the Oxygen ID to the other services? If so, will it do so by email address?
account_users = HqClient::User.all(account_id: account.id)
puts account_users.inspect
@joelind
Copy link
Author

joelind commented May 6, 2015

Illustrated here is the current invitation flow that is exposed by the HQ API, for invitations initiated by the service.

6 API calls result from this (list numbering refers to the request/response gists above, line numbering refers to the ruby client calls in user_lifecycle.rb):

  1. (line 16) creates an account
  2. (line 34) creates a project ("Project A") in that account
  3. (line 43) creates another project ("Project B") in that account.
  4. (line 56) invites an email address to Project A
  5. (line 64) invites an email address to Project B
  6. (line 76) fetches all the users in the account

At this point, we have invited the same user to 2 different projects, but the user has not yet signed in to the service, and we have no oxygen ID for the user.

Open questions.

  1. How should we remove this invited user from a project?
  2. What if some other service posts a signup with this user's oxygen id, and then we post a potentially different one? What should happen then? Is this a race condition we care about? Should HQ notify us with a PATCH? IF so, a PATCH of what? There is no identifier. Rely on email for that?
  3. What if we end up signing up the invite from #4 or #5 with a different email address than we POSTed to HQ? Post the correct oxygen_id to HQ with a signup using the old, different email address? How do we update the email address that is there?

HQ team, can you please suggest how we can deal with the three cases listed here?

@lperng
Copy link

lperng commented May 7, 2015

  1. You don't need to notify us your service project invite status change (like sending your user invites or remove your invites). Tango did the similiar until the user is oxygenated, then use our HQ user APIs to notify us. They manage the invites lifecycle themself. The reason we have invites and signups notification is because HQ is sending project admin on behalf of your service. So we need to notify you the invites, and you need to notify us the signups.
  2. If you post the second signup with different one, the HQ will reject the second oxygen id with 400.
  3. See #1 answer first, don't POST to HQ until we have oxygen id. If the user signup with different oxygen id and you can notify us with the user APIs to have one created in the project A, and one create in project B, since the two have different oxygen id. The user API will have the parameter to include email.

@gwithers
Copy link

gwithers commented May 8, 2015

But we have additional cases as well -- what about when we need to change users in terms of promoting or demoting admin capabilities as well as the delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment