Overview
The OPAS API
OPAS's APIs belong to the REpresentational State Transfer (REST) category. This allows you to perform "RESTful" operations like read, modify, add or delete data from your OPAS account.
What can I do with the OPAS API?
With the APIs, you can
Read
- Browse through customers - their details.
Write
- Create new customers.
API Endpoints and SSL
API endpoints are mapped to:
https://api.opas.com/api/v1/{path}
Authentication
How does it work?
OPAS uses JWT Authentication. This means, for authentication, you have to use the username and password.
Request
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'email=YOUR_EMAIL&password=YOUR_PASSWORD' 'https://api.opas.com/api/v1/authenticate'
If your credentials are correct and you have parmissions to use API, you get security token, which you have to provide in each following requests.
Response
{ "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjI0MDk4LCJpc3MiOiJodHRwczpcL1wvYXBpLnNhbmRib3gub3Bhcy5jb21cL2FwaVwvdjFcL2F1dGhlbnRpY2F0ZSIsImlhdCI6MTQ1MjI4MTYxMCwiZXhwIjoxNDUyMjgxOTEwLCJuYmYiOjE0NTIyODE2MTAsImp0aSI6IjllOWJlM2E5ZGUyNGRhMTU2NWI3Njg0ZjQyNWFlMTE5In0.-lK-aaFIkzFcUvJGqdeMs3EvkI1r-omr0-EB4cc3--w" }
Each token will be expired after 5 min. In that case you have to generate a new one, using the authentication request.
What API commands are used by OPAS?
OPAS APIs have been implemented JSON over HTTP and use the following REST Commands:
Command | Purpose |
---|---|
POST | Create one or more items |
GET | Fetch one or more items |
PUT | Update one or more existing items |
DELETE | Remove one or more items that already exist |
Users
If you have a permission, you can validate users by providing theirs credentials using the following APIs
Attribute | Type | Description |
---|---|---|
userId | number | Id of the customer. Read-Only |
firstName * | string | First Name of the customer. Mandatory |
lastName * | string | Last Name of the customer. Mandatory |
email * | string | Email for the customer. Mandatory |
address * | string | Street address. Mandatory |
address2 | string | Street address. |
address3 | string | Street address. |
city * | string | City name. Mandatory |
state | string | State name (Region). |
countryCode * | string | Two-letter country codes defined in ISO 3166-1 Mandatory |
postalCode | string | Postal Code (Zip Code). |
phone | string | Phone number of the customer. |
customerReferenceId * | number | Id of the customer which will be used for synchronization. Mandatory |
companyName | string | Name of the customer's company (Business Name). |
active | boolean | Status of the customer. "TRUE" - can login and use OPAS service "FALSE" - can't login and use OPAS services. Read-Only |
membershipType | string | Membership of the customer: "packageOnly", "packageAndMail", "Distributor" Read-Only |
onFraudList | boolean | Flag for a potential fraud. Read-Only |
registrationDate | date | Date of a registration of the customer. Format: 2016-01-31 Read-Only |
cancelledDate | date | Date of a cancellation of customer's account. Format: 2016-01-31 Read-Only |
cancelledReason | string | Reason of the cancellation of customer's account. Read-Only |
usAddress | array | US address the customer can use to make purchases. Read-Only |
Validate a User
To validate a User, please send a POST request to the:
https://api.opas.com/api/v1/users/validate
Request
curl -X POST -H "Authorization: Bearer YOUR_SECUTITY_TOKEN" -H "Accept: application/json" -d '{ "email":"jon.smith@gmail.com", "password":"opasPassword" }' 'https://api.opas.com/api/v1/users/validate'Response
{ "userId": 10, "firstName": "John", "lastName": "Smith", "email": "john.smith@gmail.com", "address": "3604 SE 123d ave", "address2": "", "address3": "", "city": "Gresham", "state": "", "postalCode": "", "countryCode": "US", "companyName": null, "active": true, "membershipType": "packageOnly", "onFraudList": false, "registrationDate": "2016-01-08", "cancelledDate": "0000-00-00", "cancelledReason": null, "usAddress": { "firstName": "John", "lastName": "Smith", "address": "8000 OPAS Address Rd.", "address2": "#10", "city": "Portland", "state": "Oregon", "county": "Multnomah", "postalCode": "99999", "countryCode": "US", "phone": "503-000-0000" }, "customerReferenceId": 1 }
Customers
You can create customers and view customer information using the following APIs
Attribute | Type | Description |
---|---|---|
userId | number | Id of the customer. Read-Only |
firstName * | string | First Name of the customer. Mandatory |
lastName * | string | Last Name of the customer. Mandatory |
email * | string | Email for the customer. Mandatory |
address * | string | Street address. Mandatory |
address2 | string | Street address. |
address3 | string | Street address. |
city * | string | City name. Mandatory |
state | string | State name (Region). |
countryCode * | string | Two-letter country codes defined in ISO 3166-1 Mandatory |
postalCode | string | Postal Code (Zip Code). |
phone | string | Phone number of the customer. |
customerReferenceId * | number | Id of the customer which will be used for synchronization. Mandatory |
companyName | string | Name of the customer's company (Business Name). |
active | boolean | Status of the customer. "TRUE" - can login and use OPAS service "FALSE" - can't login and use OPAS services. Read-Only |
membershipType | string | Membership of the customer: "packageOnly", "packageAndMail", "Distributor" Read-Only |
onFraudList | boolean | Flag for a potential fraud. Read-Only |
registrationDate | date | Date of a registration of the customer. Format: 2016-01-31 Read-Only |
cancelledDate | date | Date of a cancellation of customer's account. Format: 2016-01-31 Read-Only |
cancelledReason | string | Reason of the cancellation of customer's account. Read-Only |
usAddress | array | US address the customer can use to make purchases. Read-Only |
Create a Customer
To create a new Customer, please send a POST request to the https://api.sandbox.opas.com/api/v1/users
Request
curl -X POST -H "Authorization: Bearer YOUR_SECUTITY_TOKEN" -H "Accept: application/json" -d '{ "firstName":"John", "lastName":"Smith", "email":"jon.smith@gmail.com", "address":"3604 SE 123d ave", "city":"Gresham", "countryCode":"US", "customerReferenceId":"1" }' 'https://api.opas.com/api/v1/users'
Response
{ "userId": 10, "firstName": "John", "lastName": "Smith", "email": "john.smith@gmail.com", "address": "3604 SE 123d ave", "address2": "", "address3": "", "city": "Gresham", "state": "", "postalCode": "", "countryCode": "US", "companyName": null, "active": true, "membershipType": "packageOnly", "onFraudList": false, "registrationDate": "2016-01-08", "cancelledDate": "0000-00-00", "cancelledReason": null, "usAddress": { "firstName": "John", "lastName": "Smith", "address": "8000 OPAS Address Rd.", "address2": "#10", "city": "Portland", "state": "Oregon", "county": "Multnomah", "postalCode": "99999", "countryCode": "US", "phone": "503-000-0000" }, "customerReferenceId": 1 }
View a Customer
To view a Customer, please send a GET request to the:
https://api.opas.com/api/v1/users/USER_ID
or
https://api.opas.com/api/v1/customers/CUSTOMER_REFERENCE_ID
Request
curl -X GET -H "Authorization: Bearer YOUR_SECURITY_TOKEN" 'https://api.opas.com/api/v1/users/10'
or
curl -X GET -H "Authorization: Bearer YOUR_SECURITY_TOKEN" 'https://api.opas.com/api/v1/customers/1'
Response
{ "userId": 10, "firstName": "John", "lastName": "Smith", "email": "john.smith@gmail.com", "address": "3604 SE 123d ave", "address2": "", "address3": "", "city": "Gresham", "state": "", "postalCode": "", "countryCode": "US", "companyName": null, "active": true, "membershipType": "packageOnly", "onFraudList": false, "registrationDate": "2016-01-08", "cancelledDate": "0000-00-00", "cancelledReason": null, "usAddress": { "firstName": "John", "lastName": "Smith", "address": "8000 OPAS Address Rd.", "address2": "#10", "city": "Portland", "state": "Oregon", "county": "Multnomah", "postalCode": "99999", "countryCode": "US", "phone": "503-000-0000" }, "customerReferenceId": 1 }