WebApi to interface Constant Contact System and register users to an existing email list. This API uses Spring Boot as base to expose the REST end point used for the registration.
Once the application is running on a configured port it is required to submit a POST request providing the email to be registered and a valid Constant Contact list id as payload of the request.
- Method: POST
- Content-Type: application/json
- Payload (sample)
{
"listId":"0987654321",
"email":"[email protected]"
}
curl 'http://[HOST:PORT]/api/v1/contacts' -i -X POST -H 'Content-Type: application/json' -d '{"listId":"0987654321","email":"[email protected]"}'
The response object provides a general response information and the actual data is associated with the "result" property.
Resonse sample
{
"timestamp": "2019-10-21T18:56:36Z",
"status": "OK",
"code": 200,
"path": "http://localhost",
"verb": "POST",
"traceid": "20191021185636913",
"result": {
"id": "1234567890",
"email": "[email protected]",
"listId": "0987654321"
}
}
The following status codes are possible to have as part of a successful response.
- 200 : A contact exists but it was not in the email list.
- 201 : A contact did not exists so it was created and included in the email list.
- 200 : A contact exists and it is already in the email list, in this case the result object will be Null.
- 500 : Internal server error will be provided in case of errors.
The API requires two mandatory and one optional environment variable in order to operate.
- cdhapicc.apiKey: [Mandaroty] Constant Contact API Key.
- cdhapicc.accessToken: [Mandarory] Constant Contact Access Token.
- server.port: [Optional] API server port.
The API is a Java application and can be executed updating the values of the following command template.
sh -c java -Djava.security.egd=file:/dev/./urandom -jar /cdh-apicc-1.0.0.jar"
It is important to setup the environment variables before to execute the application.
- src/main : Contains the source code
- src/test : Contains the unit testing code.
- Dockerfile: Docker image definition file
The API was developed using Spring Tool Suite 4 that is base on Eclipse
- Install and open Spring Tool Suit
- Configure the required enviroment variables
- Register the Constant Contact libraries in Maven local repository by running the following commands.
mvn install:install-file -Dfile=./libs/java-sdk-5.2.3.jar -DgroupId=com.constantcontact -DartifactId=java-sdk -Dversion=5.2.3 -Dpackaging=jar
mvn install:install-file -Dfile=./libs/java-components-5.2.3.jar -DgroupId=com.constantcontact -DartifactId=java-components -Dversion=5.2.3 -Dpackaging=jar
- Debug/Run as Spring Boot application, after this step the application will be running and ready to receive request.
A Docker image can be build with the next command line.
docker build -t cdh-apicc:1.0.0 .
The following command replacing the correct values for the environment variable will start a Docker container.
docker run -p 3003:3003 --rm -e "cdhapicc.accessToken=[ACCESS_TOKEN]" -e "cdhapicc.apiKey=[API_KEY]" -e "server.port=3003" -t -i cdh-apicc:1.0.0
- 1.0.0
- Initial version
Joe Doe : X@Y
Distributed under XYZ license. See LICENSE for more information
- Fork it (https://github.com/usdot-jpo-codehub/cdh-apicc/fork)
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request
Thank you to the Department of Transportation for funding to develop this project.
- Agency: DOT
- Short Description: WebAPI to interface Constant Contact API.
- Status: Beta
- Tags: CodeHub, Constant Contact, DOT, Spring Boot, Java
- Labor Hours:
- Contact Name:
- Contact Phone: