The GovDelivery Web Service API uses basic HTTP authentication to ensure the security of data that is passed through the API. In order to use the API, you will need secure login credentials and must have the appropriate GovDelivery administrator permissions to interface with the API.
We highly recommend a dedicated generic email address for production web services API access. A dedicated account improves audit tracking, ensures consistent access, and keeps system messages out of your personal inbox.
Note: Passwords for API administrators are subject to password expiration limits set by your organization. Ensure that your username and password combination is easy to change. For example, it could be placed in a properties file, a database, or YAML file that is read by your program.
A much easier way to construct an authorization header is to use a library call to authenticate. We recommend this method for production applications. Here is an example of how to use a library call (setAuth) in PHP.
#!/usr/bin/php <?php require_once 'HTTP/Request2.php'; try { $request = new HTTP_Request2 ( 'https://stage-api.govdelivery.com/api/account/ACCOUNT_CODE/topics/TOPIC_CODE_1', HTTP_Request2::METHOD_GET, array ('ssl_verify_peer' => false, 'ssl_verify_host' => false) ); $request -> setAuth('username', 'password', HTTP_Request2::AUTH_BASIC); $response = $request -> send(); echo "Response status: " . $response -> getStatus() . "\n"; echo "Human-readable reason phrase: " . $response -> getReasonPhrase() . "\n"; echo "Response HTTP version: " . $response -> getVersion() . "\n"; echo "Response object:\n"; print_r($response) . "\n"; } catch (Exception $e) { print "\n"; echo "ERROR " . $e->getMessage() . "\n"; print_r($e) . "\n"; } ?>
Was this page helpful? Can't find what you need? Let us know