What's the right way to use `offset` with the contract query stream in the JSON API?

Hi all!

I have a websocket connection open to /v1/stream/query which works great, and now want to start making use of offset in future connections as described in the docs:

An optional offset returned by a prior query (see output examples below) may be specified before the above, as a separate body. It must be a string, and if specified, the stream will begin immediately after the response body that included that offset

So I have a connection open, I keep track of offset coming in from the server (let’s say I read "219"), and then at some time later I close a connection and open a new one. In the new connection, I first tried sending two distinct/separate message bodies like so:

{"offset": "219"}

{"templateIds": [ ... ] }

This gives me the following error message
Endpoints.InvalidUserInput: JsonReaderError. Cannot read JSON: <{"offset":"219"}>. Cause: spray.json.DeserializationException: Object is missing required member 'templateIds'

Since it seems like the endpoint was expecting templateIds as a required member, I tried various ways of combining the offset with the query. For example, I tried:

{"offset": "219", "templateIds": [ ... ] } which gives another invalid json error, and also

{"templateIds": [ ... ], "query": { "offset": "219"} } which doesn’t seem to work either.

Any help with what I might be doing wrong would be greatly appreciated! :slight_smile:

2 Likes

Sending separate messages as done in your first try is the correct syntax; you can be sure that the other formats you tried will not work.

What version of the JSON API are you using? The first cause that comes to mind would be that this version was from before we supported offsets as arguments; the error you get is exactly the error one would get in that case. (The presence of offsets in the output stream is no guarantee that your version is new enough, because we added offsets to the output stream before supporting them as arguments.)

2 Likes

Thanks for the response!

Which version were the offset arguments added in? We’re using 0.13.55

1 Like

1.0.0 was the first version; specifically, the docs you quoted do not exist in the 0.13.55 version of the docs. You can rely on this consistently, as we’ve kept the JSON API documentation up-to-date throughout its various releases.

4 Likes

Ah, I see. That solves it, then!

3 Likes