Shotgun REST API - Create Record

Creating a record

by JokerMartini

HTML

<p>
Access Token
</p>
<div id='accessOutput' class="output">waiting for action</div>
<p>
Query Results
</p>
<textarea id="queryOutput" form="output">waiting for action</textarea>

CSS

a {
    padding: 0.2em;
}
a:hover {
    background-color: #02AAEE;
}
.output {
    display: block;
    margin-top: 8px;
    padding: 1%;
    border: 1px solid #666;
    background-color: #efefef;
}
textarea {
  width: 100%;
  height: 100%;
  min-height: 500px;
}

JavaScript

function queryShotgun() {
    var headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json'
    };

    $.ajax({
        url: 'https://studiodashboard.shotgunstudio.com/api/v1/auth/access_token',
        method: 'post',

        headers: headers,
        data: {
            grant_type: 'client_credentials',
            client_id: 'queryToken',
            client_secret: '(ooiqsnkvy6vsdJnehatxpdjd'
        },
        success: function (data) {
            console.log(JSON.stringify(data));
            console.log(data);
            $('#accessOutput').html(data.access_token);

            var headers = {
            		'Accept':'application/json',
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${data.access_token}`
            };
            var body = {
              'content': 'Here is information about the bug im encountering...', 
              'subject': 'Broken Tool',
              'sg_notetype': 'Bug',
              'sg_priority': 'normal',
              'project': { 
              		"id": 93, 
                	"type": "Project"
                }, 
              'sg_status_list': 'opn',
              'note_links': [
              		{
                  	"id":1448, 
                  	"type": "Asset"
                  }]
            }

            $.ajax({
                url: 'https://studiodashboard.shotgunstudio.com/api/v1/entity/note',
                method: 'post',
                data: JSON.stringify(body),
                headers: headers,
                success: function (data) {
                    console.log(JSON.stringify(data));
                    $('#queryOutput').val(JSON.stringify(data, null, 3));
                },
                error: function (data) {
                    console.log(data);
                    $('#queryOutput').val(data.responseText);
                },
            })
        }
    })
}

window.onload = function(){
 ...