Connected Pages API Services

Using API services in Connected Pages

The connected page has access to services that are injected into the page to facilitate communication with Skedulo’s API. These services have their appropriate type definitions (for Typescript) defined in src/Services/Services.ts. Using these services is as simple as importing the relevant services from this file.

export interface Services {
  graphQL: {
    fetch<T>(operation: GraphQLRequest, endpoint?: string): Promise<T>
    mutate(operation: GraphQLRequest, endpoint?: string): Promise<GraphQLMutationResult>
    fetchMetadataFor(model: string): Promise<IntrospectionModelType>
  },
  metadata: {
    fetchVocabulary(): Promise<Vocabulary>
  },
  errorClasses: {
    GraphQLNetworkError: GraphQLError,
    GraphQLExecutionError: GraphQLError
  },
}

export interface Profile {
  tenantId: string
  userId: string
  username: string
  roles: string[]
}

export interface Credentials {
  apiServer: string
  apiAccessToken: string

  vendor: { type: 'skedulo', url: string, token: null } | { type: 'salesforce', url: string, token: string }
}

declare const skedInjected: {
  Services: Services,
  context?: string,
  profile: Profile,
  credentials: Credentials
}

export const Services = skedInjected.Services
export const context = skedInjected.context
export const profile = skedInjected.profile
export const credentials = skedInjected.credentials
  • Services.graphQL: This service allows you to send queries to Skedulo’s GraphQL API. This is the primary method of retrieving, consuming and updating data from a connected page. Refer to src/Services/DataServices.ts for usage examples. This also exposes a method for retrieving GraphQL introspection data for any given model if required.

  • Services.metadata: This service allows you to fetch data from our metadata API.

  • Services.errorClasses: This is a map that lists all possible errors that can be thrown while interacting with the available services. For example, a GraphQLExecutionError can occur if there is an error in the defined query. You can use these classes (if needed) to pattern-match (instanceof checks) in Promise catch blocks for easy and contextual error handling.

  • Context: If you are building a contextual connected page, the context would be the secondary URL path that was passed through as part of the requested page. For example, when loading a connected page with a defined page URL of /jobs with a URL in the format /jobs/001419c0-62d8-4176-b95c-13d8b68da908, the context parameter in this case would be the ID that was requested, i.e., 001419c0-62d8-4176-b95c-13d8b68da908.

  • skedInjected: This is the global variable injected into a connected page in production. You can use the provided credentials to create a HTTP instance for making requests to any Skedulo API.


Last modified August 1, 2019: updated to end of connected pages (8161217)