Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This endpoint is part of the V0 (beta) API. #18782

Closed
szabgab opened this issue Nov 25, 2022 · 6 comments
Closed

This endpoint is part of the V0 (beta) API. #18782

szabgab opened this issue Nov 25, 2022 · 6 comments

Comments

@szabgab
Copy link

szabgab commented Nov 25, 2022

Using the following Python code:

import requests

url = 'https://dev.to/api/articles'
res = requests.get(url, headers = {'Accept': 'application/vnd.forem.api-v1+json'})

print(res.headers)

I get:

{'Connection': 'keep-alive', 'Content-Length': '11027', 'Server': 'Cowboy', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '0', 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Cache-Control': 'public, no-cache', 'X-Accel-Expires': '86400', 'Content-Type': 'application/json; charset=utf-8', 'Warning': '299 - This endpoint is part of the V0 (beta) API. To start using the V1 endpoints add the `Accept` header and set it to `application/vnd.forem.api-v1+json`. Visit https://developers.forem.com/api for more information.', 'Content-Encoding': 'gzip', 'Etag': 'W/"c2cbc2f9107b10a161a149f73a980baa"', 'Content-Security-Policy': '', 'X-Request-Id': 'fb7aa4ad-741b-41db-b180-17a8816c3ad8', 'X-Runtime': '0.120087', 'Via': '1.1 vegur, 1.1 varnish, 1.1 varnish', 'Access-Control-Allow-Origin': '*', 'Accept-Ranges': 'bytes', 'Date': 'Fri, 25 Nov 2022 22:00:25 GMT', 'Age': '5', 'X-Served-By': 'cache-den8283-DEN, cache-hhn4063-HHN', 'X-Cache': 'HIT, MISS', 'X-Cache-Hits': '1, 0', 'X-Timer': 'S1669413625.468910,VS0,VE138', 'Vary': 'Accept-Encoding, Origin, X-Loggedin', 'Strict-Transport-Security': 'max-age=31557600'}

As far as I can tell I've correctly set the header but this response still tells me I use V0 and tells me what to do. (That I've done)

If I was to fetch the response using res.json() it seems the data is there, but I don't understand the warning.

Am I doing something wrong or is this a bug?

@github-actions
Copy link
Contributor

Thanks for the issue, we will take it into consideration! Our team of engineers is busy working on many types of features, please give us time to get back to you.

Feature requests that require more discussion may be closed. Read more about our feature request process on forem.dev.

To our amazing contributors: issues labeled bug are always up for grabs, but for feature requests, please wait until we add a ready for dev before starting to work on it.

To claim an issue to work on, please leave a comment. If you've claimed the issue and need help, please ping @forem-team. The OSS Community Manager or the engineers on OSS rotation will follow up.

For full info on how to contribute, please check out our contributors guide.

@fdocr
Copy link
Contributor

fdocr commented Nov 29, 2022

Am I doing something wrong or is this a bug?

Hi @szabgab, you're not doing anything wrong. That warning is a message we're using to notify everyone currently using the V0 API that a new version (V1) is available and we encourage you upgrade since we'll get rid of V0 sometime in the near future.

Documentation isn't fully available under V1 but all of V0 endpoints are available in V1 without any major differences so you can reference either of them in the mean time.

You can start using V1 exactly as you did before by passing in an Accept header with application/vnd.forem.api-v1+json (more details here). Once V0 is fully removed the Accept header will remain optional (without any warning messages) and V1 will be the default version targeted when making requests to the API.

I'm closing this issue for now, but feel free to reopen or create a new one if you find any issues with this.

@fdocr fdocr closed this as completed Nov 29, 2022
@szabgab
Copy link
Author

szabgab commented Nov 29, 2022

Thanks for the reply. Are you saying that my code used the V1 correctly?

@fdocr
Copy link
Contributor

fdocr commented Nov 30, 2022

Thanks for the reply. Are you saying that my code used the V1 correctly?

Not really. It's currently using V0 (the default). If you send the Accept header as I mentioned above it would start using V1 (explicitly requesting that version) and you'll stop receiving the warning header in the response. You'll likely see no difference in the result though since V1 includes all of the V0 endpoints, so in a way it would indeed use V1 correctly.

@szabgab
Copy link
Author

szabgab commented Jan 1, 2023

I am getting back to this issue partially as only now I noticed your reply and partially because I still see the Warning

299 - This endpoint is part of the V0 (beta) API. To start using the V1 endpoints add the Accept header and set it to application/vnd.forem.api-v1+json. Visit https://developers.forem.com/api for more information.

so I assume I am still not setting the header correctly.
Here is the code:

import requests
import os

url = 'https://dev.to/api/articles/latest?per_page=1'
headers = {}
headers['Accept'] = 'application/vnd.forem.api-v1+json'
api_key = os.environ.get('DEV_TO_API_KEY')
headers['api-key'] = api_key

res = requests.get(url, headers = headers)
if res.status_code != 200:
    print(f"Failed request. Status code {res.status_code}")
    print(res.text)
    exit(1)

print(res.headers['Warning'])

I tried to verify what my code sets so I changed the code a bit:

import requests
import os
from pprint import pprint
import json


url = 'https://httpbin.org/headers'
headers = {}
headers['Accept'] = 'application/vnd.forem.api-v1+json'
api_key = os.environ.get('DEV_TO_API_KEY')
headers['api-key'] = api_key

res = requests.get(url, headers = headers)
if res.status_code != 200:
    print(f"Failed request. Status code {res.status_code}")
    print(res.text)
    exit(1)

pprint(res.json())

This is the response I got:

{'headers': {'Accept': 'application/vnd.forem.api-v1+json',
             'Accept-Encoding': 'gzip, deflate',
             'Api-Key': 'mykey',
             'Host': 'httpbin.org',
             'User-Agent': 'python-requests/2.28.1',
             'X-Amzn-Trace-Id': 'Root=1-63b1ab9b-545032d2738ca6565c146172'}}

httpbin sees both the Accept header and the Api-Key header so I assume the dev.to API also sees it.

@szabgab
Copy link
Author

szabgab commented Jan 1, 2023

ps. I don't see where could I reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants