Solved

How to add externalId to a Timeseries

  • 2 August 2023
  • 4 replies
  • 50 views

Badge +1

I created a set of timeseries via the API. The Python examples do not show how to include an externalId nor do they say one is really needed. Looks like they need one, otherwise they don’t work in Charts. That’s all fine. My problem now is to add the externalId to existing timeseries.

I think the right way to do this is with a transform, but I can’t get it right. I can get it to preview correctly, but it fails when I run it.

My transform is:

Select
name as name,
concat(name,"123") as externalId
from
`_cdf`.`timeseries`
where dataSetId = 8883655420989208;

The error is Request with id 2463250f-1635-9a05-aa9a-709366e80349 to https://westeurope-1.cognitedata.com/api/v1/projects/rok-buandcollaborators-53/timeseries/update failed with status 400: Time series not found. Missing externalIds: [Tank-401-01-TT123].

Looks like it’s trying to query for the timeseries with that externaId when I’m trying to set the externalId. How do I get it to set the value?

icon

Best answer by Jason Dressel 2 August 2023, 18:10

View original

4 replies

Userlevel 4
Badge

@Peter Quinn ,

Try adding id to the select clause.  

id is an auto generated, internal identifier.  Yes, as you highlight, it’s good practice to specify an externalId.  externalId must be unique per CDF resource type.
-Jason

Badge +1

No urgency on this. I removed the TS and recreated them. It would be nice if the docs had an example like

ts = cdf_client.time_series.create(TimeSeries(name=tsname, data_set_id=dataset, external_id=tsname))

 

Badge +1

Not just best practice - if you want a timeseries to be visible in Charts, it needs an externalId

Userlevel 3

Hi @Peter Quinn, I have created a ticket for our documentation team. Thank you for the suggestion!

Reply