Create

Creating a record is simply a matter of sending an HTTP POST to the appropriate URL. Consider the simple example of creating a WAN Target. To accomplish this an HTTP POST request would be sent to a URL of the form:

https://rxg.dns/admin/scaffolds/wan_targets/create.xml?api_key=8f8eab...868c

with a header containing: Content-Type: application/xml and a payload of the form: <?xml version="1.0"?> <record> <name>Desired New Name</name> <targets>1.2.3.4</targets> </record> This entire process may be accomplished by using the cURLcommand line utility. Below is an example command line that demonstrates the use of cURL to execute a create through the RESTful API. curl -i -X POST -H 'Content-Type: application/xml' -d '<?xml version="1.0"?><record><name>Desired New Name</name> <targets>1.2.3.4</targets></record>' https://rxg.dns/admin/scaffolds/wan_targets/create.xml?api_key=486...a5a The RESTful API endpoint will respond with a HTTP/1.1 201 Createdthat has a Location header containing the URL to retrieve the record upon successful creation. The content of the response is a copy of the created record. ``` HTTP/1.1 201 Created Location: https://rxg.dns/admin/scaffolds/wan_targets/show/5.xml?api_key=486...876a Content-Type: application/xml; charset=utf-8 X-UA-Compatible: IE=Edge ETag: "40c13943442b4dd5646d264fdb738909" Cache-Control: max-age=0, private, must-revalidate Set-Cookie: _rxg_console_session=BAh7Ck...ea6e5; path=/; HttpOnly X-Request-Id: 43eda966fa00bd1347f48583f37e5392 X-Runtime: 0.439131 Content-Length: 155 Connection: keep-alive Server: thin 1.3.1 codename Triple Espresso

<?xml version="1.0" encoding="UTF-8"?> New Target Name A 2.2.3.4 If an error occurs and the record is not created the response will be an HTTP error status (usually `HTTP/1.1 422`) and the content will contain the error messages. For example, if the same request is run twice, then the response would take the form: HTTP/1.1 422 Content-Type: application/xml; charset=utf-8 Cache-Control: no-cache Date: Mon, 28 May 2012 17:35:23 GMT X-UA-Compatible: IE=Edge,chrome=1 Set-Cookie: _rxg_console_session=BAh7C...098b1; path=/; HttpOnly X-Request-Id: 63bb95530945b6be578eaf4485d7a337 X-Runtime: 1.800010 X-Rack-Cache: invalidate, pass Connection: close Server: thin 1.3.1 codename Triple Espresso

<?xml version="1.0" encoding="UTF-8"?> Name has already been taken Targets has already been taken ``` There are requirements that need to be met when creating records. Required fields are marked in bold in the web administrative console.

Hitting the appropriate URL without sending the required input will result in a dump of error messages that describe the requirements. For example, using cURL to send the following request: curl -i -X POST -H 'Content-Type: application/xml' -d '<?xml version="1.0"?><record><login>restfulapitest</login></record>' https://rxg.dns/admin/scaffolds/accounts/create.xml?api_key=WR5..KLw Results in the the following response. ``` HTTP/1.1 422 Content-Type: application/xml; charset=utf-8 X-UA-Compatible: IE=Edge,chrome=1 Cache-Control: no-cache Set-Cookie: _rxg_console_session=BAh...8b1; path=/; HttpOnly X-Request-Id: 63bb95530945b6be578eaf4485d7a337 X-Runtime: 1.800010 Date: Mon, 28 May 2012 14:32:18 GMT X-Rack-Cache: invalidate, pass Connection: close Server: thin 1.3.1 codename Triple Espresso

<?xml version="1.0" encoding="UTF-8"?> Email can't be blank Email is too short (minimum is 3 characters) Email is invalid Password can't be blank Password is too short (minimum is 1 characters) Password confirmation can't be blank First name can't be blank First name is too short (minimum is 2 characters) Last name can't be blank Last name is too short (minimum is 2 characters) Time must be configured unless unlimited is checked Upload quota must be configured unless unlimited is checked Download quota must be configured unless unlimited is checked Expiration must be configured unless unlimited is checked The reported errors may be used to construct a correct request to send to the RESTful API endpoint such as the following example: curl -i -X POST -H 'Content-Type: application/xml' \ -d '<?xml version="1.0"?>restfulapitest [email protected]1234567890 1234567890 apitest 1 1 1 1' https://rxg.dns/admin/scaffolds/accounts/create.xml?api_key=WR5...KLw Which results in a response of: HTTP/1.1 201 Created Location: https://rxg.dns/admin/scaffolds/accounts/show/36.xml?api_key=WR5...KLw Content-Type: application/xml; charset=utf-8 X-UA-Compatible: IE=Edge,chrome=1 ETag: "e71...4c7" Cache-Control: max-age=0, private, must-revalidate Set-Cookie: _rxg_console_session=BAh...dc6; path=/; HttpOnly X-Request-Id: 111b836e66f0883a4900d37a8c0ff42e X-Runtime: 0.040524 Date: Mon, 28 May 2012 18:55:57 GMT X-Rack-Cache: invalidate, pass Connection: close Server: thin 1.3.1 codename Triple Espresso

<?xml version="1.0" encoding="UTF-8"?> 2012-05-28T14:55:57-04:00 apikeytest y/j0nSYiWmwho4X8jj0symrxccU= [email protected] api 36 test 0 restfulapitest true dcfae2f069cb8167972225ba7c33d6ac5642fd2a active true true true 2012-05-28T14:55:57-04:00 **Accounts** must be assigned policy in order for enforcement to take effect. **Policies** are associated to **Accounts** through **Account Groups**. Associating **Accounts** with **Account Groups** is usually accomplished by setting either the `do_apply_usage_plan`or the `do_bill_and_apply_usage_plan` virtual attribute. For example: curl -i -X POST -H 'Content-Type: application/xml' -d '<?xml version="1.0"?>restfulapitest [email protected]1234567890 1234567890 apitest 3 1' https://rxg.dns/admin/scaffolds/accounts/create.xml?api_key=w1f...kkQ Notice that the usage time, usage expiration and upload/download usages are not specified because they are defined by the plan. Also notice that the `usage-plan` attribute is used to specify the desired **Usage Plan** by ID. The **Usage Plan** ID may be acquired by using the `list` action for the `usage-plans`scaffold. Note that the value of `do_apply_usage_plan` or the `do_bill_and_apply_usage_plan` virtual attributes should always be `1`. If you set the value of the`do_apply_usage_plan` or the `do_bill_and_apply_usage_plan`to anything other than `1` then the system will not execute the command at all. The following is an example of the response to a successful **Account** record creation with **Usage Plan** specification and application as shown above. HTTP/1.1 201 Created Location: https://rxg.dns/admin/scaffolds/accounts/show/24.xml?api_key=LjU...kkQ Content-Type: application/xml; charset=utf-8 X-UA-Compatible: IE=Edge,chrome=1 ETag: "4dcf...2322" Cache-Control: max-age=0, private, must-revalidate Set-Cookie: _rxg_console_session=BAh...03f; path=/; HttpOnly X-Request-Id: 5c4...841 X-Runtime: 0.039446 Date: Fri, 22 Jun 2012 21:49:40 GMT X-Rack-Cache: invalidate, pass Connection: close Server: thin 1.3.1 codename Triple Espresso

<?xml version="1.0" encoding="UTF-8"?> 2012-06-22T16:49:40-05:00 useronly pMId/QzJ.....NMc1vjObnk= [email protected] api 24 test 0 restfulapitest 37ddbeec583e.....04d94ab939f5 active true true true 2012-06-22T16:49:40-05:00 2012-07-22T16:49:40-05:00 3 ```


Cookies help us deliver our services. By using our services, you agree to our use of cookies.