Changing topic status via api to pinned-global does not work

I’m working on a python script that uses discourse API to set the status of a post to ‘pinned-globally’, following the API documentation.

The request for ‘pinned-globally’ fails with return code 400, whereas the request with status parameter set to ‘pinned’ works perfectly (i.e. I can see the post locally pinned).
This is the snippet of my code:

apiWebsite = '<my_website_URL>'
apiKey = '<secret>'
apiUsername = '<secret>'

headers = {
    'Api-Key': apiKey,
    'Api-Username': apiUsername
}


# This request works OK
# Pin the same post locally
payload = {
    'status': 'pinned',
    'enabled': 'true',
    'until': '2019-11-25T08:00:00'
}
u = requests.put(apiWebsite + '/t/29082/status', headers=headers, data=payload)
print(u.status_code)

After having set the pinned status back to false, I try to pin it globally like this.

# This request DOES NOT WORK
# Pin the same topic globally
payload = {
    'status': 'pinned-globally',
    'enabled': 'true',
    'until': '2019-11-25T08:00:00'
}
u = requests.put(apiWebsite + '/t/29082/status', headers=headers, data=payload)
print(u.status_code)

Am I missing something obvious or is it a genuine bug?

P.S. The user has sufficient privileges.

2 Likes

You cannot pin the same topic globally and locally at the same time. You can pick one or the other.

1 Like

Hi David,
of course, I just put the code like that for the sake of showing how the two requests are differing.
I’ll change the first post to make it clearer.

1 Like

Ah good :ok_hand:. Taking a look through the code, I see this which would cause a 400 error

https://github.com/discourse/discourse/blob/6e1fe22a9dded8f711fb18b8b14dad0dd921dc90/app/controllers/topics_controller.rb#L1038

I think you need pinned_globally instead of pinned-globally. Can you try that and see if it works? Looks like that’s a typo in our API documentation - I’ll get it fixed.

Edit: fixed in https://github.com/discourse/discourse_api_docs/commit/fcf0d5fb7a06728365f8dda4d2223a5ab2dfddca

5 Likes

Confirmed! :slight_smile:
Thanks a lot! :clap:

3 Likes