Getting an API key

It is possible to create a write enabled API key linked to a specific user. Let me know the user and I can create the key. Please also let me know best route to send it to you.

@Firefishy

My userid is “wambacher” and my e-mail is “wambacher@posteo.de

Regards
walter

After reading this thread, it’s still unclear for me how to get an API-Key. Could someone help with a cook recipe?

Did you plan to use the API Key for read only purposes (in which case you can request it on your own), or do you also want to create new posts using the API?

API-Key = “Read-Only”

That is exact my question.

Did try the site I posted on Getting an API key - #15 by mmd ? In step 1, you need to enter https://community.openstreetmap.org then follow along the steps 2-3.

After authorizing the call, you will see some key which you need to copy & paste back into the observablehq.com page.

2 Likes

Thanks … I struggled over the step to put the info back into the page. But now I was able to generate a (read-only) API-Key. This works for me (first test):

curl --request GET "https://community.openstreetmap.org/site.json" \
--header "User-Api-Key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
--show-error \
--include

(real API-Key masked out with ‘a’)

1 Like

I tried to create an API key with all the tricks listed here, but eventually gave up as I could not get write permissions.

So I found the following solution for me: simply sending an email to the reply-to Address of each thread works just fine, if it is sufficient to comment on existing threads.

You find the mail_to which encodes your user and the thread in each of the notifications that you receive, just check the reply-to header.

Sample code in python to send emails:

try:
    server = smtplib.SMTP(self.mail_smtp_host, self.mail_smtp_port)
    server.ehlo()
    server.starttls()
    server.login(self.mail_user, self.mail_pw)
    server.sendmail(self.mail_from, self.mail_to, msg.as_string())
    server.close()
except:
    print("failed to send mail")
    traceback.print_exc()

The email must originate from the address your account uses in this forum, of course.

UPDATE: turns out the python SMTP library does not set a date header and discourse doesn’t like that. We’ll try to set the respective postfix flag in our next try

UPDATE UPDATE: That worked! :tada:

You need to ask an admin for an API key with write permissions…

You need to ask an admin for an API key with write permissions…

Thank you, that will be our backup plan. For now, my ambition is aroused. And of course, it’s a good thing to send standard conform mails anyways.

This post was written via: cURL, Discourse API, user-api-key. The user-api-key was created by myself (not by admin).

3 Likes

This may be helpful to get an user-api-key:

And this was the script to add post #31:

#!/bin/bash
#
# Discourse API: write post 

postdata=$(cat <<EOF
{
"title": "Post written via API",
"raw": "This post was written via: cURL, Discourse API, user-api-key. The user-api-key was created by myself (not by admin).",
"topic_id": 2890,
"category": 0,
"target_recipients": "",
"target_usernames": "",
"archetype": "",
"created_at": "",
"embed_url": "",
"external_id": ""
}
EOF
)

echo "postdata =\n$postdata"

set -o verbose

curl \
--url 'https://community.openstreetmap.org/posts.json' \
--request 'POST' \
--show-error \
--include \
--header 'Content-Type: application/json' \
--header 'User-Api-Key: ********************************' \
--header 'Accept: application/json' \
--data "$postdata"
6 Likes

This post was written via: cURL, Discourse API, user-api-key. The user-api-key was created by myself with Script for generating an user API key for discourse. · GitHub .

Wonderful, thank you @toc-rox - It works perfectly. Instead of the webservice, I used the script from the gist and added write permissions (not sure if that is needed or not).

Thanks all!

I shall update the my Schwerpunkt stuff to post automatically, too :slight_smile:

Kai

1 Like

This post was written via: cURL, Discourse API, user-api-key. The user-api-key was created by myself (not by admin).

Hello,

I’d like to create an API Key to retrieve posts programatically, but I can’t see any way to generate that from my user settings. Do I need to have some kind of level to be able to see it? Is there any way I can get one?