E
E
Elizabeth Lawrence2020-07-17 22:27:46
JavaScript
Elizabeth Lawrence, 2020-07-17 22:27:46

How to get the city id using the GET /regions method via the Yandex API?

Good evening. The Yandex API has a method for getting the city id by the passed city name ( GET /regions ). The task is simply to form a GET request of the format:

curl -i -H 'Content-Type: application/xml' 'https://api.partner.market.yandex.ru/v2/regions.xml?name=Ивановка'

If I send a simple request, I get a "401 Not authorized" error. Therefore, all requests require a header:
Authorization: OAuth oauth_token="авторизационный_токен", oauth_client_id="идентификатор_приложения"

And as a result I get a "405 Method Not Allowed" error. Since this is a complex request, the browser sends a preliminary request using the OPTIONS method, and, as it were, Yandex writes me an error that this method is not available. I'm confused, if someone has an idea, please tell me how to solve this ailment?
Basically my request looks like this:
let webApiUrl = 'https://api.partner.market.yandex.ru/v2/regions.xml?name=Москва;
      const resgetRegion = await axios.get(webApiUrl, { headers: {"Authorization" : 'OAuth oauth_token=XxX, oauth_client_id=XxX'} });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2020-07-17
@Svoeobraznaya

Since this is a complex request, the browser sends a preliminary request

it is not clear what other preliminary request ?
you just need to add one more header with authorization to each
of your requests. Can you send a request through curl itself?
curl -i 'https://api.partner.market.yandex.ru/v2/regions.json?name=Moskow' \
     -H 'Content-Type: application/json' \
     -H 'Authorization: OAuth oauth_token="__ТОКЕН__", oauth_client_id="__ИД__"'

ps
and it’s not bad, when you ask, to throw a link to the source of where you get it all from to save time for yourself and others

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question