Hello,
I’m trying to create a subitem for a parent item, and I have difficulties with a mutation who work on playground but not in my code.
(TypeScript)
I suggest looking into using GraphQL Variables rather than string substitution. The issue you’re running into is the metric_value JSON being substituted isn’t properly escaped for quotes when the string gets serialized by the client for the request.
These let you define placeholders the graphql server will use values from a “variables” object thats included with the request when it processes, rather than string substitution.
Your names can be whatever you want them to be, but i prefer being specific to the query
GraphQLClient supports a variables object being supplied alongside the query. Another advantage of variables is you don’t have to allocate a string every time its called, you can create the query string outside the query function.
Also add the "“API-Version”: “2023-10"” header. 2023-07 is going to be removed from service on January 15th, so you want to make sure you’re testing against the new API - which does have a lot of breaking changes.
One change in 2023-10 is item IDs are now ID type instead of Int type. ID can be a string or int. This means you no longer have to coerce your query responses where the ID is a string to a number to use them in a mutation.
Just sharing the above because you may want to abstract out the column_id because those can get changed over time on accident, or you may want to reuse code in some way on another board. So that makes it a bit easier to edit since you might be able to make the column_id a constant someplace if you use it in many places. Or as you advance and create recipes and custom triggers you can abstract further. (Maybe you want to store this data to several boards one day, having a reusable recipe lets you reuse the code, the recipe just passes the column for that board to your code). I don’t know what you’re working on, just pointing out some more “advanced” techniques to think about before you box yourself in inadvertently.