Edits history of script submission #22728 for ' Get Import Set Result (servicenow)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    function authHeader(auth: RT.Servicenow) {
      return auth.token
        ? `Bearer ${auth.token}`
        : `Basic ${btoa(`${auth.username}:${auth.password}`)}`
    }
    
    /**
     * Get Import Set Result
     * Fetch the outcome of a prior import row by the staging-row sys_id returned by Insert Into Import Set (result.sys_id), returning the transform result (target table, status, target record link).
     */
    export async function main(
      auth: RT.Servicenow,
      staging_table: string,
      sys_id: string
    ) {
      const url = new URL(
        `${auth.instance_url}/api/now/import/${staging_table}/${sys_id}`
      )
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: authHeader(auth),
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 days ago