How to use Oauth2 with epic48’s API
Follow these instructions to set up your application to authenticate to epic48’s API and access users’ data
Create a sign-in button that links to the authentication page of the API. Ideally, I think this should be done in a pop-up window but we’ll have to flush that out.
https://api.epic48.com/oauth/authorize?client_id=reg.conexsys.com&redirect_uri=https://reg.conexsys.com/lo/congress17&response_type=code
The user will log in with their email address and password, and then be presented with the option to approve or decline CONEXSYS’ request for data. (To Do: these screen needs a css update and much wording)
Once authorized and allowed, the user will be sent back to https://reg.conexsys.com/lo/congress17?code=[authorization_code] this authorization code can now be traded in by your app for a login.
POST Request to: https://api.epic48.com/token
Include header:
Authorization: Basic base64_encode("reg.conexsys.com:")
Include post data:
grant_type: authorization_code
code: [authorization_code] // provided from the users' request
redirect_uri: https://reg.conexsys.com/lo/congress17
curl example:
# curl 'https://api.epic48.com/token' -H 'Authorization: Basic cmVnLmNvbmV4c3lzLmNvbTo=' --data 'grant_type=authorization_code&code=T318vYjtBO8PzWDeKkdKvAVG6RgZxiglUzzWGK5r&redirect_uri=https%3A%2F%2Freg.conexsys.com%2Flo%2Fcongress17'
The reply will provide you with a JSON formatted response which has the oauth access_token which will allow you to use the API as the user:
{"access_token":"YVIt06qLVpx1KLa3S6DFS6qOru3cl9uqv0t33hAN","token_type":"Bearer","expires_in":3600,"refresh_token":"6aRTqZ4G96PB3oc4lPcfPqsqt8C9t91uyUdBvxzb"}
This can now be used by your app to request the users’ contact information which will be returned in JSON+API format.
GET Request to: https://api.epic48.com/user
Include header:
Authorization: Bearer [access_token]
Sample response:
{ "links": { "self": "https://api.epic48.com/contact/25799" }, "data": { "type": "contact", "id": "25799", "attributes": { "prefix": "Mr.", "first": "Colin", "middle": "", "last": "Vanmierlobensteyn", "suffix": "", "birthdate": null, "googleid": null }, "relationships": { "company": { "data": [ { "type": "company", "id": 25799 } ] }, "number": { "data": [ { "type": "number", "id": 93931 }, { "type": "number", "id": 97294 } ] }, "email": { "data": [ { "type": "email", "id": 26361 } ] } } }, "included": [ { "type": "contact", "id": 63396, "attributes": { "prefix": "", "first": "Deborah", "middle": "", "last": "Dugan", "suffix": "", "birthdate": null, "googleid": null, "pivot": { "companyID": 25799, "contactID": 63396, "title": "", "description": null, "created_at": "2016-04-06 15:29:38", "updated_at": "2016-04-06 15:29:38" } }, "links": { "self": "https://api.epic48.com/contact/63396" } }, { "type": "contact", "id": 25799, "attributes": { "prefix": "Mr.", "first": "Colin", "middle": "", "last": "Vanmierlobensteyn", "suffix": "", "birthdate": null, "googleid": null, "pivot": { "companyID": 25799, "contactID": 25799, "title": "", "description": null, "created_at": "2016-04-06 15:29:38", "updated_at": "2016-04-06 15:29:38" } }, "links": { "self": "https://api.epic48.com/contact/25799" } }, { "type": "number", "id": 84401, "attributes": { "numberrel": "companies", "relID": 25799, "name": "Alternate Phone", "countrycode": "1", "areacode": "905", "prefix": "405", "suffix": "1791", "extension": "", "other": "" }, "links": { "self": "https://api.epic48.com/number/84401" } }, { "type": "number", "id": 87111, "attributes": { "numberrel": "companies", "relID": 25799, "name": "Alternate Phone", "countrycode": "1", "areacode": "905", "prefix": "405", "suffix": "8543", "extension": "", "other": "" }, "links": { "self": "https://api.epic48.com/number/87111" } }, { "type": "number", "id": 54124, "attributes": { "numberrel": "companies", "relID": 25799, "name": "Business - Toll Free", "countrycode": "1", "areacode": "800", "prefix": "661", "suffix": "5319", "extension": "", "other": "" }, "links": { "self": "https://api.epic48.com/number/54124" } }, { "type": "number", "id": 22932, "attributes": { "numberrel": "companies", "relID": 25799, "name": "Fax", "countrycode": "1", "areacode": "905", "prefix": "405", "suffix": "9870", "extension": "0", "other": "0" }, "links": { "self": "https://api.epic48.com/number/22932" } }, { "type": "number", "id": 22931, "attributes": { "numberrel": "companies", "relID": 25799, "name": "Phone", "countrycode": "1", "areacode": "905", "prefix": "405", "suffix": "8415", "extension": "0", "other": "0" }, "links": { "self": "https://api.epic48.com/number/22931" } }, { "type": "address", "id": 40896, "attributes": { "addressrel": "companies", "relID": 25799, "title": "Business Address from Trade", "aptunit": "34", "number": 7050, "street": "Bramalea Road", "line2": "", "line3": "", "city": "Mississauga", "province": "ON", "postalcode": "L5S 1S9", "country": "Canada", "latitude": "43.6848713", "longitude": "-79.6636513", "type": "address", "id": 40896 }, "links": { "self": "https://api.epic48.com/address/40896" } }, { "type": "email", "id": 36902, "attributes": { "emailrel": "companies", "relID": 25799, "name": null, "address": "ddugan@conexsysregistration.com", "lastsend": null, "unavailable": "N", "optin": 0, "emailcrt": null }, "links": { "self": "https://api.epic48.com/email/36902" } }, { "type": "website", "id": 32002, "attributes": { "websiterel": "companies", "relID": 25799, "title": "", "url": "http://www.conexsysregistration.com/", "lastvisit": null, "unavailable": "N" }, "links": { "self": "https://api.epic48.com/website/32002" } }, { "type": "company", "id": 25799, "attributes": { "companyname": "CONEXSYS", "operatingname": "CONEXSYS", "startupdate": "0000-00-00 00:00:00", "dateclosed": null, "pivot": { "contactID": 25799, "companyID": 25799, "title": "", "description": null, "created_at": "2016-04-06 15:29:38", "updated_at": "2016-04-06 15:29:38" } }, "links": { "self": "https://api.epic48.com/company/25799" }, "relationships": { "contact": { "data": [ { "type": "contact", "id": 63396 }, { "type": "contact", "id": 25799 } ] }, "number": { "data": [ { "type": "number", "id": 84401 }, { "type": "number", "id": 87111 }, { "type": "number", "id": 54124 }, { "type": "number", "id": 22932 }, { "type": "number", "id": 22931 } ] }, "address": { "data": [ { "type": "address", "id": 40896 } ] }, "email": { "data": [ { "type": "email", "id": 36902 } ] }, "website": { "data": [ { "type": "website", "id": 32002 } ] } } }, { "type": "number", "id": 93931, "attributes": { "numberrel": "contacts", "relID": 25799, "name": "Business - Mobile", "countrycode": "1", "areacode": "416", "prefix": "886", "suffix": "5446", "extension": "", "other": "" }, "links": { "self": "https://api.epic48.com/number/93931" } }, { "type": "number", "id": 97294, "attributes": { "numberrel": "contacts", "relID": 25799, "name": "Phone Extension", "countrycode": "1", "areacode": "905", "prefix": "405", "suffix": "8415", "extension": "8423", "other": "" }, "links": { "self": "https://api.epic48.com/number/97294" } }, { "type": "email", "id": 26361, "attributes": { "emailrel": "contacts", "relID": 25799, "name": "", "address": "colin@conexsys.com", "lastsend": null, "unavailable": "N", "optin": 0, "emailcrt": null }, "links": { "self": "https://api.epic48.com/email/26361" } } ] }