diff --git a/templates/zerver/api.html b/templates/zerver/api.html index e84d210176..0727eb7cb2 100644 --- a/templates/zerver/api.html +++ b/templates/zerver/api.html @@ -46,7 +46,7 @@ to pull out the resulting HTML :) #}

Stream message

-
curl {{ external_api_uri }}/v1/messages \
+
curl {{ external_api_uri_subdomain }}/v1/messages \
     -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
     -d "type=stream" \
     -d "to=Denmark" \
@@ -55,7 +55,7 @@ to pull out the resulting HTML :)
 

Private message

-
curl {{ external_api_uri }}/v1/messages \
+
curl {{ external_api_uri_subdomain }}/v1/messages \
     -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
     -d "type=private" \
     -d "to=hamlet@example.com" \
@@ -106,19 +106,19 @@ to pull out the resulting HTML :)
 

Stream message

zulip-send --stream Denmark --subject Castle \
 --user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5{% if api_site_required %} \
---site={{ external_api_uri }}{% endif %}
+--site={{ external_api_uri_subdomain }}{% endif %}

Private message

zulip-send hamlet@example.com \
 --user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5{% if api_site_required %} \
---site={{ external_api_uri }}{% endif %}
+--site={{ external_api_uri_subdomain }}{% endif %}

Passing in the message on the command-line

If you'd like, you can also provide the message on the command-line with the -m flag, as follows:

zulip-send --stream Denmark --subject Castle \
 -m "Something is rotten in the state of Denmark." \
 --user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5{% if api_site_required %} \
---site={{ external_api_uri }}{% endif %}
+--site={{ external_api_uri_subdomain }}{% endif %}
 

You can omit the user{% if api_site_required %}, api-key, and @@ -149,8 +149,6 @@ to pull out the resulting HTML :)

[api]
 key=BOT_API_KEY
 email=BOT_EMAIL_ADDRESS
-{% if api_site_required %}site={{ external_api_uri }}{% endif %}
+{% if api_site_required %}site={{ external_api_uri_subdomain }}{% endif %}
{% endblock %} - - diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index be75b655cd..848331a6dc 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -269,7 +269,6 @@ def accounts_accept_terms(request): 'special_message_template' : special_message_template }, request=request) - @authenticated_json_post_view @has_request_variables def json_invite_users(request, user_profile, invitee_emails_raw=REQ("invitee_emails")): diff --git a/zerver/views/integrations.py b/zerver/views/integrations.py index 407f265cad..6361c69294 100644 --- a/zerver/views/integrations.py +++ b/zerver/views/integrations.py @@ -26,6 +26,11 @@ class ApiURLView(TemplateView): add_api_uri_context(context, self.request) return context + +class APIView(ApiURLView): + template_name = 'zerver/api.html' + + class IntegrationView(ApiURLView): template_name = 'zerver/integrations.html' @@ -46,13 +51,17 @@ class IntegrationView(ApiURLView): def api_endpoint_docs(request): # type: (HttpRequest) -> HttpResponse + context = {} # type: Dict[str, Any] + add_api_uri_context(context, request) + raw_calls = open('templates/zerver/api_content.json', 'r').read() calls = ujson.loads(raw_calls) langs = set() for call in calls: - call["endpoint"] = "%s/v1/%s" % (settings.EXTERNAL_API_URI, call["endpoint"]) + call["endpoint"] = "%s/v1/%s" % (context["external_api_uri_subdomain"], + call["endpoint"]) call["example_request"]["curl"] = call["example_request"]["curl"].replace("https://api.zulip.com", - settings.EXTERNAL_API_URI) + context["external_api_uri_subdomain"]) response = call['example_response'] if '\n' not in response: # For 1-line responses, pretty-print them diff --git a/zproject/urls.py b/zproject/urls.py index 30dbb55c52..a73ffe218c 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -7,7 +7,7 @@ import os.path import zerver.forms from zproject import dev_urls from zproject.legacy_urls import legacy_urls -from zerver.views.integrations import IntegrationView +from zerver.views.integrations import IntegrationView, APIView from zerver.lib.integrations import WEBHOOK_INTEGRATIONS # NB: There are several other pieces of code which route requests by URL: @@ -93,7 +93,7 @@ i18n_urls = [ url(r'^register/(?P\S+)/$', 'zerver.views.accounts_home_with_domain'), # API and integrations documentation - url(r'^api/$', TemplateView.as_view(template_name='zerver/api.html')), + url(r'^api/$', APIView.as_view(template_name='zerver/api.html')), url(r'^api/endpoints/$', 'zerver.views.integrations.api_endpoint_docs'), url(r'^integrations/$', IntegrationView.as_view()), url(r'^about/$', TemplateView.as_view(template_name='zerver/about.html')),