Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions docs/action_network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,148 @@ You can then call various endpoints:

# Get a specific wrapper
specific_wrapper = an.get_wrapper('wrapper_id')

# Get all surveys
all_surveys = an.get_surveys()

# Get a specific survey
specific_survey = an.get_survey('survey_id')

# Create a survey
survey_payload = {
"title": "My Free Survey",
"origin_system": "FreeSurveys.com"
}
created_survey = an.create_survey(survey_payload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth including what created_survey looks like?

see created_tagging above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


created_survey = {
"identifiers": [
"action_network:1234"
],
"created_date": "2014-03-26T15:26:30Z",
"modified_date": "2014-03-26T15:26:30Z",
"title": "My Free Survey",
"total_responses": 0,
"origin_system": "FreeSurveys.com",
"action_network:hidden": false,
"_embedded": {
"osdi:creator": {
"given_name": "John",
"family_name": "Doe",
"created_date": "2014-03-20T21:04:31Z",
"modified_date": "2014-03-20T21:04:31Z",
"identifiers": [
"action_network:1234"
],
"email_addresses": [
{
"primary": true,
"address": "jdoe@mail.com",
"status": "subscribed"
}
],
"phone_numbers": [
{
"primary": true,
"number": "12021234444",
"number_type": "Mobile",
"status": "subscribed"
}
],
"postal_addresses": [
{
"primary": true,
"address_lines": [
"1600 Pennsylvania Ave"
],
"locality": "Washington",
"region": "DC",
"postal_code": "20009",
"country": "US",
"language": "en",
"location": {
"latitude": 32.249,
"longitude": -73.0339,
"accuracy": "Approximate"
}
}
],
"languages_spoken": [
"en"
],
"_links": {
"self": {
"href": "https://actionnetwork.org/api/v2/people/1234"
},
"osdi:attendances": {
"href": "https://actionnetwork.org/api/v2/people/1234/attendances"
},
"osdi:signatures": {
"href": "https://actionnetwork.org/api/v2/people/1234/signatures"
},
"osdi:submissions": {
"href": "https://actionnetwork.org/api/v2/people/1234/submissions"
},
"osdi:donations": {
"href": "https://actionnetwork.org/api/v2/people/1234/donations"
},
"osdi:outreaches": {
"href": "https://actionnetwork.org/api/v2/people/1234/outreaches"
},
"osdi:taggings": {
"href": "https://actionnetwork.org/api/v2/people/1234/taggings"
},
"action_network:responses": {
"href": "https://actionnetwork.org/api/v2/people/1234/responses"
},
"curies": [
{
"name": "osdi",
"href": "https://actionnetwork.org/docs/v2/{rel}",
"templated": true
},
{
"name": "action_network",
"href": "https://actionnetwork.org/docs/v2/{rel}",
"templated": true
}
]
}
}
},
"_links": {
"osdi:creator": {
"href": "https://actionnetwork.org/api/v2/people/1234"
},
"self": {
"href": "https://actionnetwork.org/api/v2/surveys/1234"
},
"action_network:responses": {
"href": "https://actionnetwork.org/api/v2/surveys/1234/responses"
},
"action_network:record_response_helper": {
"href": "https://actionnetwork.org/api/v2/surveys/1234/responses"
},
"action_network:embed": {
"href": "https://actionnetwork.org/api/v2/surveys/1234/embed"
},
"curies": [
{
"name": "osdi",
"href": "https://actionnetwork.org/docs/v2/{rel}",
"templated": true
},
{
"name": "action_network",
"href": "https://actionnetwork.org/docs/v2/{rel}",
"templated": true
}
]
}
}

# Update a survey
updated_survey = an.update_survey('survey_id', survey_payload)

***********
SQL Mirror
Expand Down
74 changes: 74 additions & 0 deletions parsons/action_network/action_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,80 @@ def update_submission(self, form_id, submission_id, data):
f"forms/{form_id}/submissions/{submission_id}", data=json.dumps(data)
)

# Surveys
def get_surveys(self, limit=None, per_page=25, page=None, filter=None):
"""
Survey resources are sometimes presented as collections of surveys.
For example, calling the surveys endpoint will return a collection
of all the surveys associated with your API key.
`Args:`
limit:
The number of entries to return. When None, returns all entries.
per_page:
The number of entries per page to return. 25 maximum.
`Returns:`
"""
if page:
return self._get_page("surveys", page, per_page, filter)
return self._get_entry_list("surveys", limit, per_page, filter)

def get_survey(self, survey_id):
"""
`Args:`
survey_id:
The unique id of the survey
`Returns:`
A JSON with the survey entry
`Documentation Reference`:
https://actionnetwork.org/docs/v2/surveys
"""
return self.api.get_request(f"surveys/{survey_id}")

def create_survey(self, data):
"""
`Args:`
data:
The payload for creating the survey
{
"title": "My Free Survey",
"origin_system": "FreeSurveys.com"
}
OR
The payload for creating the survey with a creator link
{
"title": "My Free Survey",
"origin_system": "FreeSurveys.com"
"_links" : {
"osdi:creator" : {
"href" : "https://actionnetwork.org/api/v2/people/[person_id]"
}
}
}
`Returns:`
A JSON with the created survey entry
`Documentation Reference`:
https://actionnetwork.org/docs/v2/surveys
"""
return self.api.post_request("surveys", data=json.dumps(data))

def update_survey(self, survey_id, data):
"""
`Args:`
survey_id:
The unique id of the survey
data:
The payload for updating the survey
{
"title": "My Free Survey",
"origin_system": "FreeSurveys.com",
}
`Returns:`
A JSON with the updated survey entry
`Documentation Reference`:
https://actionnetwork.org/docs/v2/surveys
"""
return self.api.post_request(f"surveys/{survey_id}", data=json.dumps(data))

# Tags
def get_tags(self, limit=None, per_page=None):
"""
Expand Down
Loading
Loading