Skip to content

Commit

Permalink
Added function export async function graphqlFilterOnMarketingInitiati…
Browse files Browse the repository at this point in the history
…ve(marketingInitiative) (#64)

Which calls the persisted query gmo/filter-on-marketing-initiative
with example parameters

{
  "marketingInitiative": "FY24Q1-Q2_AdobeExpress_level Up"
}

https://author-p108396-e1046543.adobeaemcloud.com/graphql/execute.json/gmo/filter-on-marketing-initiative%3BmarketingInitiative=FY24Q1-Q2_AdobeExpress_level%20Up
  • Loading branch information
TyroneAEM authored Apr 11, 2024
1 parent f34bff4 commit 793951c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ export async function graphqlCampaignByName(campaignName) {
});
}

export async function graphqlFilterOnMarketingInitiative(marketingInitiative) {

const baseApiUrl = `${await getGraphqlEndpoint()}/graphql/execute.json`;
const projectId = 'gmo';
const queryName = 'filter-on-marketing-initiative';
const encodedMarketingInitiative = encodeURIComponent(marketingInitiative);
const encodedSemiColon = encodeURIComponent(';');
//persisted query URLs have to be encoded together with the first semicolon
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}${encodedSemiColon}marketingInitiative=${encodedMarketingInitiative}`;
const jwtToken = await getBearerToken();

// Return the fetch promise chain so that it can be awaited outside
return fetch(graphqlEndpoint, {
method: 'GET',
headers: {
Authorization: jwtToken,
},
}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
}).then(data => {
return data; // Make sure to return the data so that the promise resolves with it
}).catch(error => {
console.error('Error fetching data: ', error);
throw error; // Rethrow or handle error as appropriate
});
}



async function getGraphqlEndpoint() {
const result = await getAdminConfig();
Expand Down

0 comments on commit 793951c

Please sign in to comment.