I have configured an interface specifically for utilization with an asynchronous function:
interface PostScriptTagResponse {
script_tag : {
readonly id : number
, src : string
, event : string
, readonly created_at : string
, readonly updated_at : string
, display_scope? : string
}
}
protected async createScriptTag(): Promise<PostScriptTagResponse|null> {
try {
const data: PostScriptTagResponse = await fetch(fetchUrl, {
method: 'post'
, headers: {
"X-Shopify-Access-Token": this.generalToken
, "Content-Type": "application/json"
}
, body: {
script_tag : {
src: `${this.serverHost}/server/frontEndScriptControl.js`
, event: "onload"
, display_scope: "online_store"
}
}
}).json();
return data.script_tag;
// Property "script_tag" is missing in type {detailed interface spec here}
// but required in type "PostScriptTagResponse"
}
catch (e) {
// removed
}
}
Upon revisiting the aforementioned code snippet, I believe the structure to be accurate. Could there be a flaw in my understanding? Below is an example of the response I anticipate from the fetch request:
https://help.shopify.com/en/api/reference/online-store/scripttag#create-2019-10
HTTP/1.1 201 Created
{
"script_tag": {
"id": 870402694,
"src": "https://djavaskripped.org/fancy.js",
"event": "onload",
"created_at": "2019-10-16T16:14:18-04:00",
"updated_at": "2019-10-16T16:14:18-04:00",
"display_scope": "all"
}
}