Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

POST Request to Visual Studio Online REST API with AJAX

$
0
0

Dear all,

I'm trying to make a POST request to the VSO REST API by using jQUery and AJAX. Here's my code:

        var bearing = "Bearer " + $('textarea#accesstoken').val();

        var dataJSON = {"name": "FabrikamTravel","description": "Frabrikam travel app for Windows Phone","capabilities": {"versioncontrol": {"sourceControlType": "Git"},"processTemplate": {"templateTypeId": "6b724908-ef14-45cf-84f8-768b5384da45"}}};

        $.ajax({
            url: 'https://chriwil.visualstudio.com/DefaultCollection/_apis/projects?api-version=2.0-preview',
            dataType: 'JSON',
            type: 'POST',
            data: JSON.stringify(dataJSON),
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", bearing)
            },
            success: function(data){
                console.log(data)
            },
            error: function(jqXHR, textStatus, errorThrown)   {
                console.log(textStatus);
            }
        });

When I send the request, I get the message: "Failed to load resource: the server responded with a status of 403 (Forbidden)".

Does anyone know how to fix this? It works with a GET request fine.

Thank you.

Christopher


Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>