Git Product home page Git Product logo

Comments (14)

AlfHou avatar AlfHou commented on May 27, 2024 1

I see! Yeah, I tried to use the offers API but couldn't quite figure it out
Maybe I'll try it again in the future, but I kind of found another way that works atm. 😄

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024 1

I’m creating a lowfare calendar for train prices (like the one Norwegian has for their planes). So I need a way to get the prices for a given journey on a given day.

I think the prices for short train journeys (i.e. Lillestrøm - Oslo) stay more or less the same, but it is relevant for longer journeys (Oslo - Bergen).

Check out my repo for a example of what I am doing 😄

from sdk.

draperunner avatar draperunner commented on May 27, 2024 1

To get the ID, you also need to do make the search through Offers using the /search/graphql endpoint. All you need to do is to point the hosts.journeyplanner config to this new URL:

 const sdk = new EnturService({
     clientName: '<YOUR_CLIENT_NAME>',
+    hosts: {
+        journeyplanner: 'https://api.staging.entur.io/sales/v1/offers/search'
+    }
 })

The trip patterns will then have an id you can use to fetch offers from the endpoint you mentioned.

I suggest you use the staging URL for testing and respect rate limits, so we don't need to block you as well ;). Check out the throttler utility if you're bulk calling a lot of calls.

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024 1

Burning the midnight oil and responding to (I assume) work related questions late at night? Props!

Thank you very much for the fast response. I’ll probably use C# and .NET Core for querying the API and then cache the results on my server, but thank you very much. I think I’ll figure it out by looking at the source code here.

I’ll make sure to follow the rate limits and try to implement some kind of throttler on my backend. Looking at your constraints in rateLimits.js, it seems like I am allowed to do quite a lot of calls.

from sdk.

draperunner avatar draperunner commented on May 27, 2024 1

It's something in the GraphQL query that makes offers unable to fetch product information. It works with the query used in @entur/sdk v1.0-next, but not the one in v0 or in your curl. Try removing fields and see if you suddenly get an answer.

from sdk.

draperunner avatar draperunner commented on May 27, 2024

Hi! You're right. This SDK is currently only for journey planning. If you want prices and offers, you can use the Offers API. There are some guides there, but depending on what you want to do, they might not all be relevant. Maybe I can help if you give me some more details. You can also always contact us by using the feedback form on developer.entur.org or by sending an email to [email protected].

Thanks for reaching out! I agree, functions for getting prices would be convenient. :)

from sdk.

draperunner avatar draperunner commented on May 27, 2024

I'm interested in the details of what you're trying to do, if you'd like to share more details. Maybe we can improve the docs and SDK further. :)

Are you trying to show prices for journeys (trip patterns) or for certain zones? For a certain operator (Ruter, Vy or others)? For one adult, or special combinations?

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024

Hi @draperunner. Vy blocked the ip of the server my project was running on so i figured I'd try moving over to Entur.

I am trying to get an offer for this trip using this endpoint: https://api.entur.io/sales/v1/offers/search/trip/trip-pattern/{id}. My problem is I don't know how to get the id the endpoint requires. In the link I posted there is an ID that says "NSB:Line:41", however that doesn't seem to be working.

Any help would be appreciated :)

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024

So. I manage to query https://api.staging.entur.io/sales/v1/offers/search/graphql and get back this id: 5e16c6300718be000132710a.

However when i try to query https://api.staging.entur.io/sales/v1/offers/search/trip/trip-pattern/5e16c6300718be000132710a I receive the response: { "message": "Internal Server Error", "description": "An unexpected error occurred: Failed fetching offers for trip pattern id 5e16c6300718be000132710a" }.

Any suggestions?

from sdk.

draperunner avatar draperunner commented on May 27, 2024

A trip pattern is only cached for about 15 minutes, so if the ID 5e16c6300718be000132710a is older than this, you won't get any offers. You need to do the trip search again, and immediately ask for offers after receiving the results. I guess that's the issue. :)

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024

I don't think that's it.
I am executing the queries right after each other.

For example, you could try this

curl --location --request POST 'https://api.staging.entur.io/sales/v1/offers/search/graphql' --header 'Content-Type: application/json' --data-raw '{"query":"{\r\n  trip(\r\n    from: {place: \"NSR:StopPlace:548\"\r\n    }\r\n\r\n    to: {\r\n      place:\"NSR:StopPlace:337\"\r\n    }\r\n    dateTime: \"2020-01-09T00:00:00+0100\",\r\n    modes: [rail]\r\n    \r\n    \r\n    \r\n  )\r\n\r\n#### Requested fields\r\n  {\r\n    tripPatterns {\r\n      startTime\r\n      duration\r\n\r\n          legs {\r\n            mode\r\n            distance\r\n            line {\r\n              id\r\n              publicCode\r\n              authority{\r\n                name\r\n              }\r\n            }\r\n          }\r\n    }\r\n  }\r\n}","variables":{}}' | grep -Po '"id": *"\K[^"]*' | awk 'NR==1{print$1}' | xargs -I id curl --location --request GET 'https://api.staging.entur.io/sales/v1/offers/search/trip/trip-pattern/id'

to see an example of what I mean

from sdk.

draperunner avatar draperunner commented on May 27, 2024

You're right, something's wrong with the query from the SDK. I'm not sure exactly what. But it works with our v1 beta version. You could try npm install @entur/sdk@next and use that version. There are some breaking changes though, and more might come.

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024

I guess this is the wrong place to ask. I am not really looking to use the SDK. I just want to call the API. Is there something wrong with the offers API? And is there somewhere else I should rather ask for help?

from sdk.

AlfHou avatar AlfHou commented on May 27, 2024

I tried removing some fields from the post to the /sales/v1/offers/search/graphql graphql endpoint and got my query down to this

 trip(
   from: {place: "NSR:StopPlace:548"
   }

   to: {
     place:"NSR:StopPlace:337"
   }
   dateTime: "2020-01-10T00:00:00+0100",
   numTripPatterns: 20,
   modes: [rail]
   
   
   
 )

#### Requested fields
 {
   tripPatterns {
     startTime
     duration
   }
 }

I managed to get the sales/v1/offers/search/trip/trip-pattern{id} to respond. However the offers array it returns is empty. I'll explore some more.

from sdk.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.