https://slingdata.io logo
Hello @flarco
# sling-help
m
Hello @flarco I'm writing an API Spec with dynamic endpoints, and I'm trying to use a state variable to construct the jmsepath/jq expression inside the
response.records
map. However I'm getting an error when running the replication. It seems like it is not injecting the state variable before passing the expression to jmsepath.
Copy code
# Excerpt from spec.yaml

defaults:
  state:
    url: 'https://api.lightspeedapp.com/API/V3/Account/{inputs.account_id}/{state.endpoint_name}.json'
  request:
    url: '{state.url}'

dynamic_endpoints:
  - iterate: '["Employee","CustomerType"]'
    into: 'state.endpoint_name'
    endpoint:
      name: '{snake(state.endpoint_name)}'
      response:
        records:
          jmespath: '{state.endpoint_name}[]'
          primary_key: '{snake(state.endpoint_name)}_id'
        processors:
          - expression: 'object_casing(record, "snake")'
            output: 'record'
The error message:
Copy code
3:19PM INF execution failed

~ could not perform request
could not evaluate jmespath "{state.endpoint_name}[]" => SyntaxError: Expected tColon, received: tDot

context canceled
f
hey @mariovw, that's an interesting approach, currently the value in jmespath/jq doesn't render expressions/variables (they only accept raw strings). That's a nice feature, let me see if we can add for next release.
m
Thanks @flarco, for now I found a workaround, but let me know if you include it in a release so I can update the spec to make it more robust for my use case. Also, can API Specs be defined using Python?
f
Yes, already done for next release. For API Spec via Python, not possible currently. Let me consider this.
m
Great, thanks! Will be on the lookout for the next release. I was asking for API Spec via Python to know if it was currently possible, as it would have been another way of achieving the dynamic endpoint. But with the change you already did then I would not need API Spec via Python for now.
Hey @flarco I noticed you added "JMESPath/JQ safe rendering with state variables" in v1.5.10, but I'm still getting the same error even after updating
Copy code
$ sling --version
Version: 1.5.11

$ sling run -r test.replication.yaml --streams customer_type
1:02AM INF Sling CLI | https://slingdata.io
1:02AM INF Sling Replication | LIGHTSPEED_API -> STAGING | customer_type
1:02AM INF connecting to target database (duckdb)
1:02AM INF connecting to source api (api)
1:02AM INF execution failed


fatal:
~ failure running replication (see docs @ https://docs.slingdata.io/sling-cli)
--------------------------- customer_type ---------------------------
~ could not stream requests
~ could not perform request
could not evaluate jmespath "{state.endpoint_name}[]" => SyntaxError: Expected tColon, received: tDot
f
@mariovw yes you're correct, there was a piece missing in the implementation. Should be good now, is tested. you can use the [dev build](https://github.com/slingdata-io/sling-cli?tab=readme-ov-file#automated-dev-builds) if you'd like.