Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Converting C# syntax HTTP call to JS syntax call

I got an HTTP call implemented with C# which calls to an Azure API:

public async Task<string> CheckPipelineRunStatus(string pipelineId, string pipelineRunId, CancellationToken cancellationToken = default)
    {
        string responseBody = "";

        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                Convert.ToBase64String(
                    System.Text.ASCIIEncoding.ASCII.GetBytes(
                        string.Format("{0}:{1}", "", _token))));

            var requestUrl = $"https://dev.azure.com/{_organization}/{_project}/_apis/pipelines/{pipelineId}/runs/{pipelineRunId}?api-version={_api_version}";

            using (HttpResponseMessage response = await client.GetAsync(requestUrl, cancellationToken))
            {
                response.EnsureSuccessStatusCode();
                responseBody = await response.Content.ReadAsStringAsync();
            }
        }
        return responseBody;
    }

I need to do the same call in a Javascript call and I'm not sure how exactly am I suppose to send the Authorization header.

Here's what I got so far without the header (question in comment inside the code):

async function checkPipelineStatus(url)
{
    var params =  { 
        method: 'GET',
        headers: { 
            'Content-Type': 'application/json',
             //is the auth supposed to be here? what to do with that 64base string?
        }
    };
    const fetchResult = await fetch(url, params);
    const result = await fetchResult.text();
    if (!fetchResult.ok) 
    {
       throw result;
    }
    return result;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As requested, here's your JavaScript code with the header inserted:

async function checkPipelineStatus(url)
{
    let base64Credentials = btoa(':' + _token);
    var params =  { 
        method: 'GET',
        headers: { 
            'Content-Type': 'application/json',
            // Insert your own Base64 credentials here:
            'Authorization': `Basic ${base64Credentials}`
        }
    };
    const fetchResult = await fetch(url, params);
    const result = await fetchResult.text();
    if (!fetchResult.ok) 
    {
       throw result;
    }
    return result;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!