Shields: API badge (Scratch)

Created on 3 Jul 2020  路  5Comments  路  Source: badges/shields

:clipboard: Description
My idea is that there should be a badge that collects info from an API. Is there already a way to do this?

:link: Data
Here is the API I want to work with: https://scratchdb.lefty.one/v2/user/info/Ani-Xan and the info I want to extract is the "followers"

:microphone: Motivation
I want to use this on some forums and use this on multiple websites.

question

Most helpful comment

I have about 0 coding experience and only have used API's on no-code platforms. How exactly would I connect the API?

You don't have to do any coding. If you scroll down to the Dynamic badge builder section on the homepage as I suggested in my previous response, you can use the page to let it build the badge url for you.

Specifically, I think you'd end up with a badge url something like this
https://img.shields.io/badge/dynamic/json?color=blue&label=followers&query=%24.statistics.followers&url=https%3A%2F%2Fscratchdb.lefty.one%2Fv2%2Fuser%2Finfo%2FAni-Xan

The badge route you'd use is https://img.shields.io/badge/dynamic/json, and then you include query parameters to specify other inputs.

The badge builder section there helps you construct the badge url, instead of you having to do it manually. The color and label query parameters are pretty self explanatory, and you can plug in whatever you want there. The url param is where you specify the endpoint, which in your case is https://scratchdb.lefty.one/v2/user/info/Ani-Xan (just make sure to uri encode it, which becomes https%3A%2F%2Fscratchdb.lefty.one%2Fv2%2Fuser%2Finfo%2FAni-Xan) and then lastly you use the query param to specify the jsonpath query that grabs the desired data point. In your case I believe that's the values of followers key under the statistics key, so your jsonpath is accordingly $.statistics.followers (again uri encoded as %24.statistics.followers)

image

All 5 comments

Is there already a way to do this?

Yup! Depending on your needs, you could leverage our Endpoint badge or our Dynamic Json badge (scroll down to the Dynamic section on the main https://shields.io/ page)

Is there already a way to do this?

Dynamic Json badge (scroll down to the Dynamic section on the main https://shields.io/ page)

I have about 0 coding experience and only have used API's on no-code platforms. How exactly would I connect the API?

I have about 0 coding experience and only have used API's on no-code platforms. How exactly would I connect the API?

You don't have to do any coding. If you scroll down to the Dynamic badge builder section on the homepage as I suggested in my previous response, you can use the page to let it build the badge url for you.

Specifically, I think you'd end up with a badge url something like this
https://img.shields.io/badge/dynamic/json?color=blue&label=followers&query=%24.statistics.followers&url=https%3A%2F%2Fscratchdb.lefty.one%2Fv2%2Fuser%2Finfo%2FAni-Xan

The badge route you'd use is https://img.shields.io/badge/dynamic/json, and then you include query parameters to specify other inputs.

The badge builder section there helps you construct the badge url, instead of you having to do it manually. The color and label query parameters are pretty self explanatory, and you can plug in whatever you want there. The url param is where you specify the endpoint, which in your case is https://scratchdb.lefty.one/v2/user/info/Ani-Xan (just make sure to uri encode it, which becomes https%3A%2F%2Fscratchdb.lefty.one%2Fv2%2Fuser%2Finfo%2FAni-Xan) and then lastly you use the query param to specify the jsonpath query that grabs the desired data point. In your case I believe that's the values of followers key under the statistics key, so your jsonpath is accordingly $.statistics.followers (again uri encoded as %24.statistics.followers)

image

Wow, you're smart. Thank you SO much for helping me.

Cheers! Closing this out now as the original inquiry appears to have been answered

Was this page helpful?
0 / 5 - 0 ratings

Related issues

calebcartwright picture calebcartwright  路  3Comments

najeeb-ur-rehman picture najeeb-ur-rehman  路  3Comments

bruno-garcia picture bruno-garcia  路  3Comments

chadwhitacre picture chadwhitacre  路  4Comments

irgolic picture irgolic  路  3Comments