Hello team, We are trying to add/replace an externalID with some custom field and value and some how we are not able to achieve through the python script through api. We are getting an error like this ‘{'code': 400, 'message': 'Query string must be provided'}’ Could you please suggest or advise how I can add/update/replace with externalId to the factsheet. Can we create and assign value to externalId while fact sheet creation through API?? please advise. Below is my python script.
import requests
import json
api_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_url = 'https://app.leanix.net/services/mtm/v1/oauth2/token'
#request_url = 'https://app.leanix.net/services/pathfinder/v1/graphql'
## Authentication:
response = requests.post(auth_url, auth=('apitoken', api_token),
data={'grant_type': 'client_credentials'})
response.raise_for_status()
access_token = response.json()['access_token']
auth_header = 'Bearer ' + access_token
header = {'Authorization': auth_header}
# #value: "{\"uffective\":\"FYCAPEX-9999\"}"
mutation_string = """"
mutation {
updateFactSheet( id: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
patches: [{
op: replace,
path: "/externalId",
value: "{\”uffective\":\"FYCAPEX-9999\"}"
}],
validateOnly: true) {
factSheet {
... on Project {
externalId {
externalId
}
}
}
}
}
"""
mutation_string1= """
mutation ($patches: [Patch]!) {
result: updateFactSheet(id: "XXXXXXXXXXXXXXXXXXXXXXXX",
patches: $patches, validateOnly: true) {
factSheet {
... on Project {
externalId {
externalId
}
}
}
}
}
"""
data_mutation = {"query": mutation_string1}
json_post = json.dumps(data_mutation)
print("json_post",json_post)
import time
start_time = time.time()
graphql_api_url = "https://XXX.leanix.net/services/pathfinder/v1/graphql"
query_params={
"op": "replace",
"path": "/externalId",
"value": "{\”uffective\":\"FYCAPEX-9999\"}" }
query_params1={ "patches": [ {
"op": "replace",
"path": "/externalId",
"value": "{\”uffective\":\"FYCAPEX-9999\"}"
}
]
}
client = requests.Session()
response = client.post(
graphql_api_url,
headers={"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"},
json=json_post,params=query_params
)
elapsed_time = time.time() - start_time
print(response)
print(response.json())
---------------------------
We want this way to be created as shown in image.

we also tried by passing the below query to the script with out any query param but it says same error. mutation {
updateFactSheet( id: "b09e2c6d-4d2a-4f2d-afbf-4076ebdcd9d2",
patches: [{
op: replace,
path: "/externalId",
value: "{\"uffective\":\"FYCAPEX-9999\"}"
}],
validateOnly: true) {
factSheet {
... on Project {
externalId {
externalId
}
}
}
}
}
Could you please advise as soon as possible . Awaiting your reply..