valapi / node-valapi

Valorant API wrapper for nodejs
https://valapi.github.io
MIT License
18 stars 7 forks source link

how to get items name #5

Closed Cansiny0320 closed 1 year ago

Cansiny0320 commented 1 year ago

i have got item id '167481de-4732-b44a-06ad-938625015abe' ,so how can i get this item name?

Cansiny0320 commented 1 year ago

sorry, it's not a bug,please remove bug label

KTNG-3 commented 1 year ago

how did you get that item id? that is difficult to find.

Cansiny0320 commented 1 year ago

there is my code

import { AuthClient } from '@valapi/auth'
import { Client as WebClient } from '@valapi/web-client'

import { Region } from '@valapi/lib'

const config = {
  region: Region.Default.Asia_Pacific,
  throwOnError: true,
}

const authClient = new AuthClient(config)

const login = async () => {
  await authClient.login('xxx', 'xxx')
}

const main = async () => {
  await login()
  const subject = authClient.getSubject()
  const json = authClient.toJSON()
  const webClient = new WebClient(config)
  webClient.fromJSON(json)
  const data = await webClient.Store.getStorefront(subject)

  console.log(data.data.SkinsPanelLayout.SingleItemOffers[0])
}

main()
KTNG-3 commented 1 year ago

here you are, try it first maybe it doesn't work.

const getOffers = await WebClient.Store.getOffers();

async function getOffersOf(ItemsId: string) {
    let Store_Display_Name = "";
    let Store_Display_Icon = "";
    const GetWeaponSkinLevel = await ValorantApiCom.Weapons.getSkinLevels();
    for (const _SkinLevel of GetWeaponSkinLevel.data.data) {
            if (_SkinLevel.uuid === ItemsId) {
                Store_Display_Name = _SkinLevel.displayName;
                Store_Display_Icon = _SkinLevel.displayIcon;

                break;
            }
        }

    return {
        Name: Store_Display_Name,
        Icon: Store_Display_Icon
    };
}

const AllOffers = (await WebClient.Store.getStorefront("subject")).data.SkinsPanelLayout.SingleItemOffers;

for (const ofItemID in AllOffers) {
    const ItemID = AllOffers[ofItemID];
    const _Offer = await getOffersOf(ItemID);
}
Cansiny0320 commented 1 year ago

here you are, try it first maybe it doesn't work.

const getOffers = await WebClient.Store.getOffers();

async function getOffersOf(ItemsId: string) {
    let Store_Display_Name = "";
    let Store_Display_Icon = "";
    const GetWeaponSkinLevel = await ValorantApiCom.Weapons.getSkinLevels();
    for (const _SkinLevel of GetWeaponSkinLevel.data.data) {
            if (_SkinLevel.uuid === ItemsId) {
                Store_Display_Name = _SkinLevel.displayName;
                Store_Display_Icon = _SkinLevel.displayIcon;

                break;
            }
        }

    return {
        Name: Store_Display_Name,
        Icon: Store_Display_Icon
    };
}

const AllOffers = (await WebClient.Store.getStorefront("subject")).data.SkinsPanelLayout.SingleItemOffers;

for (const ofItemID in AllOffers) {
    const ItemID = AllOffers[ofItemID];
    const _Offer = await getOffersOf(ItemID);
}

it's not work, this request https://pd.ap.a.pvp.net/store/v2/storefront/subject 400 status

Cansiny0320 commented 1 year ago

maybe it need auth?

KTNG-3 commented 1 year ago

yeah

Cansiny0320 commented 1 year ago

but there is not ApiClient.fromJSON, any way else?

Cansiny0320 commented 1 year ago

there is my code now

import { AuthClient } from '@valapi/auth'
import { Client as WebClient } from '@valapi/web-client'
import { Client as ValorantApi } from '@valapi/valorant-api.com'

import { Region } from '@valapi/lib'

const config = {
  region: Region.Default.Asia_Pacific,
  throwOnError: true,
}

const authClient = new AuthClient(config)

const login = async () => {
  await authClient.login('xxx', 'xxx')
}

const main = async () => {
  await login()
  const subject = authClient.getSubject()
  const json = authClient.toJSON()
  const webClient = new WebClient(config)
  const ApiClient = new ValorantApi({
    language: 'zh-CN',
  })
  webClient.fromJSON(json)
  // ApiClient.fromJSON(json)
  const data = await webClient.Store.getStorefront(subject)

  const getOffers = await webClient.Store.getOffers()

  async function getOffersOf(ItemsId: string) {
    let Store_Display_Name = ''
    let Store_Display_Icon = ''
    const GetWeaponSkinLevel = await ApiClient.Weapons.getSkinLevels()
    for (const _SkinLevel of GetWeaponSkinLevel.data.data!) {
      if (_SkinLevel.uuid === ItemsId) {
        Store_Display_Name = _SkinLevel.displayName as string
        Store_Display_Icon = _SkinLevel.displayIcon

        break
      }
    }

    return {
      Name: Store_Display_Name,
      Icon: Store_Display_Icon,
    }
  }

  const AllOffers = (await webClient.Store.getStorefront('subject')).data.SkinsPanelLayout
    .SingleItemOffers

  for (const ofItemID in AllOffers) {
    const ItemID = AllOffers[ofItemID]
    const _Offer = await getOffersOf(ItemID)
    console.log(_Offer)
  }
}

main()
KTNG-3 commented 1 year ago

yes like that, put my code after your code

Cansiny0320 commented 1 year ago

@KTNG-3 like this? but it still not working now

KTNG-3 commented 1 year ago
import { AuthClient } from "@valapi/auth";
import { Client as WebClient } from "@valapi/web-client";
import { Client as ValorantApi } from "@valapi/valorant-api.com";

import { Region } from "@valapi/lib";

const config = {
    region: Region.Default.Asia_Pacific,
    throwOnError: true
};

const authClient = new AuthClient(config);

const login = async () => {
    await authClient.login("Username", "Password");
};

const main = async () => {
    await login();
    const subject = authClient.getSubject();
    const webClient = WebClient.fromJSON(authClient.toJSON());
    const ApiClient = new ValorantApi({
        language: "zh-CN"
    });

    const data = await webClient.Store.getStorefront(subject);

    // const getOffers = await webClient.Store.getOffers();

    async function getOffersOf(ItemsId: string) {
        let Store_Display_Name = "";
        let Store_Display_Icon = "";
        const GetWeaponSkinLevel = await ApiClient.Weapons.getSkinLevels();
        if (GetWeaponSkinLevel.data.data) {
            for (const _SkinLevel of GetWeaponSkinLevel.data.data) {
                if (_SkinLevel.uuid === ItemsId) {
                    Store_Display_Name = _SkinLevel.displayName as string;
                    Store_Display_Icon = _SkinLevel.displayIcon;

                    break;
                }
            }
        }

        return {
            Name: Store_Display_Name,
            Icon: Store_Display_Icon
        };
    }

    const AllOffers = data.data.SkinsPanelLayout
        .SingleItemOffers;

    for (const ofItemID in AllOffers) {
        const ItemID = AllOffers[ofItemID];
        const _Offer = await getOffersOf(ItemID);

        console.log(_Offer);
    }
};

main();
KTNG-3 commented 1 year ago

is it work?

Cansiny0320 commented 1 year ago

The code works fine, but the information is not the same as my store information

KTNG-3 commented 1 year ago

hmm, its seem a problem

Cansiny0320 commented 1 year ago

I can't tell whether I got the wrong id or the id is wrongly mapped to the displayname

Cansiny0320 commented 1 year ago

there is my log

89b68205-4fe5-2434-a731-e5a734bd4a7a Undercity Bulldog
5f059d7e-413c-445c-e36f-9a9791fba5b0 Origin Crescent Blade
33d3c906-4305-19cf-8770-1eb5207482cc Rush Judge
1b94d997-4db6-014f-4cb8-c1b4df7d7ebc Smite Judge
KTNG-3 commented 1 year ago

so you need "displayname" in your language or the item is wrong

Cansiny0320 commented 1 year ago

i find it

 const webClient = new WebClient(config)
 webClient.fromJSON(authClient.toJSON())

This needs to be written in order to correctly set the region in config

 const webClient = WebClient.fromJSON(authClient.toJSON());

Writing config like this doesn't work

Cansiny0320 commented 1 year ago

it is ok now, thx