# V2 API parameter for OSM restrictions?

**URL:** <https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031>\
**Category:** openrouteservice\
**Created:** [October 26, 2019, 1:14pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031 "2019-10-26T13:14:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serg9](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/serg9/32/2242_2.png) [@Serg9](https://ask.openrouteservice.org/u/Serg9)\
**Post date:** [October 26, 2019, 1:14pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/1 "2019-10-26T13:14:40Z")

</div>

What is an API v2 parameter to force the service to take restrictions into account. I have tried _optimized=false_ or _preference=recommended_, no result. E.g. right only restriction is ignored:  
[https://api.openrouteservice.org/v2/directions/driving-car?api\_key=mykey&start=8.69276,49.415092&end=8.692138,49.414484&preference=recommended](https://api.openrouteservice.org/v2/directions/driving-car?api_key=mykey&start=8.69276,49.415092&end=8.692138,49.414484&preference=recommended)

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [November 11, 2019, 3:55pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/2 "2019-11-11T15:55:06Z")

</div>

Yeah, there’s unfortunately only a hacky way to do this and not with GET. You’ll have to use POST for this:

Just specify some `options` and it’ll turn off speed-up, i.e. contraction hierarchies. Try `{"options": {"avoid_countries": [1]}}`, which would try to avoid Afghanistan. Or try another country you definitely don’t want to pass:

> **[GitHub - GIScience/openrouteservice-docs: :memo: This repository stores the...](https://github.com/GIScience/openrouteservice-docs#country-list)**
>
> :memo: This repository stores the swagger specifications of the openrouteservice API. Browse to swagger for a detailed overview. - GitHub - GIScience/openrouteservice-docs: :memo: This repository s...

---

<div class="post-metadata">

**Author:** ![Serg9](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/serg9/32/2242_2.png) [@Serg9](https://ask.openrouteservice.org/u/Serg9)\
**Post date:** [November 12, 2019, 1:27pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/3 "2019-11-12T13:27:19Z")

</div>

@nils, thank you. _preference=recommended_ worked with POST request. At least setting the option gives a different route .

---

<div class="post-metadata">

**Author:** ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)\
**Post date:** [November 12, 2019, 1:31pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/4 "2019-11-12T13:31:17Z")

</div>

Think I misread. What kind of restrictions are you looking for? Turn restrictions?

`recommended` helps triggering turn restrictions I think, but could have some side effects I’m still not clear about. It might be `fastest` with turn restrictions. But probably more complicated than that. I think @HendrikLeuschner can help here.

---

<div class="post-metadata">

**Author:** ![Serg9](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/serg9/32/2242_2.png) [@Serg9](https://ask.openrouteservice.org/u/Serg9)\
**Post date:** [November 12, 2019, 1:48pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/5 "2019-11-12T13:48:15Z")

</div>

Yes, I want a route which respects [https://wiki.openstreetmap.org/wiki/Relation:restriction#Road\_signs](https://wiki.openstreetmap.org/wiki/Relation:restriction#Road_signs).

---

<div class="post-metadata">

**Author:** ![HendrikLeuschner](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/hendrikleuschner/32/509_2.png) [@HendrikLeuschner](https://ask.openrouteservice.org/u/HendrikLeuschner)\
**Post date:** [November 18, 2019, 4:27pm UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/6 "2019-11-18T16:27:33Z")

</div>

You currently should have the option to turn off contraction based speedups by using avoid countries as Nils said, or using e.g. avoid ferries. Contraction based speedups have no turn restrictions at the moment. It should trigger the use of ALT.  
Does it produce the results youre looking for that way?

---

<div class="post-metadata">

**Author:** ![Serg9](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/serg9/32/2242_2.png) [@Serg9](https://ask.openrouteservice.org/u/Serg9)\
**Post date:** [November 19, 2019, 8:21am UTC](https://ask.openrouteservice.org/t/v2-api-parameter-for-osm-restrictions/1031/7 "2019-11-19T08:21:56Z")

</div>

@HendrikLeuschner, I managed to get a correct route complying with turn restriction using POST API :

> import requests  
> api\_key=“my key”
> 
> url = ‘[https://api.openrouteservice.org/v2/directions/driving-car/geojson](https://api.openrouteservice.org/v2/directions/driving-car/geojson)’  
> payload = {  
> ‘coordinates’: [[8.69276,49.415092],[8.692138,49.414484]]  
> , ‘preference’ : ‘recommended’  
> }
> 
> import json  
> r = requests.post(url, data=json.dumps(payload)  
> , headers = {  
> “Content-Type”: “application/json”  
> , “Authorization” : api\_key  
> , “Accept” : “application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8”  
> }  
> )

[This route at demo site](https://maps.openrouteservice.org/directions?n1=49.414886&n2=8.692712&n3=17&a=49.415092,8.69276,49.414484,8.692138&b=0&c=2&k1=en-US&k2=km)
