Discuss Scratch

PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

So, this is an accept invitation button:


I'm working on a project involving the scratch API and it requires that I can accept a studio invite with a http request.

So, if you're confused I'm asking for, what is the URL for accepting a studio invitation? obviously containing the required headers and cookies for example api.scratch.mit.edu/users/griffpatch/messages/count/ for @griffpatch's message count

My friend said it's `scratch.mit.edu/site-api/users/curators-in/{studioId}/add/` but it doesn't seem to work, or maybe its my code?

Here's the code I use for making the request:

print("importing...")

import scratchattach as scratch3
import time
import os
import requests

def accept_invitation(studio, user):
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
"x-csrftoken": "a",
"x-requested-with": "XMLHttpRequest",
"referer": f"https://scratch.mit.edu/site-api/users/curators-in/{studio}/add/",
}
cookies = {
"scratchsessionsid" : session.session_id,
"scratchcsrftoken" : "a",
"scratchlanguage" : "en",
"accept": "application/json",
"Content-Type": "application/json",
}
response = requests.put(f"https://scratch.mit.edu/site-api/users/curators-in/{studio}/add/", headers=headers, cookies=cookies)
return response.text

print("logging in...")

session = scratch3.login("username", "password")

print("making request...")

print(accept_invitation(34023334, "PhilHub"))

Last edited by PhilHub (Oct. 24, 2023 06:49:43)

caftingdead261
Scratcher
100+ posts

Studio "accept invite" API request?

you could try adding the api.___ at the start?
mybearworld
Scratcher
1000+ posts

Studio "accept invite" API request?

You're probably going to need a session ID on that request.
PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

mybearworld wrote:

You're probably going to need a session ID on that request.
“obviously containing the required headers and cookies”
PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

caftingdead261 wrote:

you could try adding the api.___ at the start?
Nope, this one uses the other depreciated version. scratch.mit.edu/site-api/
PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

mybearworld wrote:

You're probably going to need a session ID on that request.
Unfortunately even though I added a session id it still doesn't work. I mean it does go through without any traceback errors, but it returns:

importing...
logging in...
making request...

<!DOCTYPE html>

<html>
<head>

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl+'';f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-NBMRDKQ');</script>
<!-- End Google Tag Manager -->

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

<meta name="google-site-verification" content="m_3TAXDreGTFyoYnEmU9mcKB4Xtw5mw6yRkuJtXRKxM" />
<title>Scratch - Imagine, Program, Share</title>

<link rel="stylesheet" href="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/vendor/redmond/jquery.ui.all.css" />

<link href="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/css/main.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" href="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__//css/handheld.css" media="handheld, only screen and (max-device-width:480px)"/>


<link href="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/css/pages/http-errors.css" rel="stylesheet">

<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__//js/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/js/lib/underscore-min.js"></script>

<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__//js/gaq-ga4.js"></script>
<script>
window.console||(window.console={log:$.noop,error:$.noop,debug:$.noop}); // ensure console fails gracefully when missing
var sessionCookieName = 'scratchsessionsid';



_gaq.push(['_setCustomVar', 2, 'status', 'logged_in', 2]);




</script>
<script type="text/javascript">
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

function setCookie(name, value, days) {
var expires;

if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
</script>

<script>


var Scratch = Scratch || {};
Scratch.INIT_DATA = Scratch.INIT_DATA || {};



Scratch.INIT_DATA.ADMIN = false;
Scratch.INIT_DATA.LOGGED_IN_USER = {

model: {
username: 'PhilHub-contribute',
username_truncated: 'PhilHub-con...',
has_outstanding_email_confirmation: 'false',

id: 99255746,
profile_url: '/users/PhilHub-contribute/',
thumbnail_url: '//uploads.scratch.mit.edu/users/avatars/99255746.png'

},

options: {

authenticated: true


}
};

Scratch.INIT_DATA.project_comments_enabled = true;
Scratch.INIT_DATA.gallery_comments_enabled = true;
Scratch.INIT_DATA.userprofile_comments_enabled = true;

Scratch.INIT_DATA.BROWSERS_SUPPORTED = {

chrome: 35,
firefox: 31,
msie: 8,
safari: 7
};

Scratch.INIT_DATA.TEMPLATE_CUES = {

unsupported_browser: true,
welcome: true,
confirmed_email: false
};







Scratch.INIT_DATA.IS_IP_BANNED = false;

Scratch.INIT_DATA.GLOBAL_URLS = {
'media_url': '//uploads.scratch.mit.edu/',
'static_url': '//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/',
'static_path': '/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/'
}

Scratch.INIT_DATA.IS_SOCIAL = true;

</script>


<meta property="og:type" content="website" />

<meta property="og:description" content="Make games, stories and interactive art with Scratch. (scratch.mit.edu)"/>



<meta property="og:title" content="Scratch - Imagine, Program, Share"/>
<meta property="og:url" content="https://scratch.mit.edu/site-api/users/curators-in/34023334/add/?usernames=PhilHub-contribute/" />


</head>

<body class="" >

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NBMRDKQ" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

<!--[if lte IE 8]>
<div class="unsupported-browser banner" data-cue="unsupported_browser">
<div class="container">
<span>Scratch supports Internet Explorer 9+. We suggest you upgrade to <a href="/info/faq/#requirements">a supported browser</a>, <a href="/scratch2download/">download the offline editor</a>, or <a href="https://en.scratch-wiki.info/wiki/List_of_Bug_Workarounds">read about common workarounds</a>.</span>
</div>
</div>
<![endif]-->
<div id="pagewrapper">


<div id="topnav" >
<div class="innerwrap">
<div class="container">
<a href="/" class="logo"><span class="scratch"></span></a>
<ul class="site-nav">
<li><a id="project-create" href="/projects/editor/?tip_bar=home">Create</a></li><li><a href="/explore/projects/all">Explore</a></li><li ><a href="/ideas">Ideas</a></li><li class="last"><a href="/about/">About</a></li>
</ul>

<form class="search" action="/search/projects" method="get" class="search">
<input type="submit" class="glass" value="">
<input id="search-input" type="text" placeholder="Search" name="q" >
</form>

<ul class="account-nav"></ul>
<script type="text/template" id="template-account-nav-logged-out">
<ul class="account-nav" >
<li class="join-scratch"><a href="/join">Join Scratch</a></li><li id="login-dropdown" class="sign-in dropdown"><span data-toggle="dropdown" class="dropdown-toggle"><span>Sign in</span></span><div class="popover bottom dropdown-menu"><div class="arrow"></div><div class="popover-content" ><form method="post" id="login" action="#"><label for="username">Username</label><input type="text" id="login_dropdown_username" name="username" maxlength="30" class="wide username" /><label for="password" class="password">Password</label><input type="password" name="password" class="wide password" /><div class="ajax-loader" style="display:none; float: left;"></div><button type="submit">Sign in</button><span class="forgot-password"><a href="/accounts/password_reset/">Need help?</a></span><div class="error"></div></form></div></div></li><li data-control="modal-login" class="sign-in mobile"><span>Sign in</span></li>
</ul>
</script>
<script type="text/template" id="template-account-nav-logged-in">
<ul class="account-nav logged-in"><li class="messages"><a title="messages - updates and notices" href="/messages" class="messages-icon"><span class="notificationsCount none">0</span></a></li><li class="my-stuff"><a title="my stuff - manage projects and studios" href="/mystuff/" class="mystuff-icon"></a></li><li class="logged-in-user dropdown"><span class="user-name dropdown-toggle" data-toggle="dropdown"><img class="user-icon" src="<%- LOGGED_IN_USER.model.thumbnail_url %>" width="24" height="24"><%- LOGGED_IN_USER.model.username_truncated %><span class="caret"></span></span><div class="dropdown-menu blue" ><ul class="user-nav"><li><a href="<%- LOGGED_IN_USER.model.profile_url %>">Profile</a></li><li><a href="/mystuff/">My Stuff</a></li><% if (LOGGED_IN_USER.model.is_educator){ %><li><a href="/educators/classes/">My Classes</a></li><% } %><% if (LOGGED_IN_USER.model.is_student){ %><li><a href="/classes/<%- LOGGED_IN_USER.model.classroom_id %>/">My Class</a></li><% } %><li><a href="/accounts/settings/">Account settings</a></li><li id="logout" class="logout divider"><form method="post" action="/accounts/logout/"><input type='hidden' name='csrfmiddlewaretoken' value='a' /><input type="submit" value="Sign out"></form></li></ul></div></li></ul>
</script>
<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/js/account-nav.js"></script>
</div>
<iframe class="iframeshim" frameborder="0" scrolling="no"><html><head></head><body></body></html></iframe>
</div><!-- innerwrap -->
</div>


<div class="privacy-update banner" style="display:none;">
<div class="container">
<span>The Scratch privacy policy has been updated, effective May 25, 2023. You can see the new policy <a href="/privacy_policy">here</a>.</span>
<div class="close">x</div>
</div>
</div>

<div class="confirm-email banner" data-cue="confirmed_email" style="display:none;">
<div class="container">
<span><a id="confirm-email-popup" href="#">Confirm your email</a> to enable sharing. <a href="/info/faq/#accounts">Having trouble?</a></span>
<div class="close">x</div>
</div>
</div>

<div class="email-outage banner" style="display:none; background-color:#FF661A;">
<div class="container">
<span>We are experiencing a disruption with email delivery. If you are not receiving emails from us, please try after 8am EST.</span>
<div class="close">x</div>
</div>
</div>


<div class="container" id="content">
<div id="alert-view"></div>

<!-- templates/404.html block main-content -->
<div class="box" id="page-404" >
<div class="box-head">
</div>
<div class="box-content">
<img src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/images/404-giga.png" style="margin:20px;padding: 10px;">
<div class="box-header">
<h1>Whoops! Our server is Scratch'ing its head</h1>
</div>
<p>We couldn't find the page you're looking for. Check to make sure you've typed the url correctly.
<br />You can try searching for what you're looking for here:
<form action="/search/projects" method="get" class="search"><span class="glass"><i></i></span>

<input type="text" placeholder=Search name="q"> </form>
</p>
<h3 class="status-code">404</h3>
</div>
</div>
<!-- end block main-content -->

</div>




</div>
<div id="footer">
<div class="container">
<style>
#footer ul.footer-col li {
list-style-type:none;
display: inline-block;
width: 184px;
text-align: left;
vertical-align: top;
}

#footer ul.footer-col li h4 {
font-weight: bold;
font-size: 14px;
color: #666;
}

</style>
<ul class="clearfix footer-col">
<li>
<h4>About</h4>
<ul>
<li><a href="/about/">About Scratch</a></li>
<li><a href="/parents/">For Parents</a></li>
<li><a href="/educators/">For Educators</a></li>
<li><a href="/developers">For Developers</a></li>
<li><a href="/info/credits/">Our Team</a></li>
<li><a href="https://www.scratchfoundation.org/supporters">Donors</a></li>
<li><a href="/jobs/">Jobs</a></li>
<li><a href = "/donate">Donate</a></li>
</ul>
</li>
<li>
<h4>Community</h4>
<ul>
<li><a href = "/community_guidelines/">Community Guidelines</a></li>
<li><a href = "/discuss/">Discussion Forums</a></li>
<li><a href = "http://wiki.scratch.mit.edu/">Scratch Wiki</a></li>
<li><a href = "/statistics/">Statistics</a></li>
</ul>
</li>
<li>
<h4>Resources</h4>
<ul>
<li><a href = "/ideas">Ideas</a></li>
<li><a href = "/info/faq/">FAQ</a></li>
<li><a href = "/download">Download</a></li>
<li><a href = "/contact-us/">Contact Us</a></li>
</ul>
</li>
<li>
<h4>Legal</h4>
<ul>
<li><a href="/terms_of_use/">Terms of Use</a></li>
<li><a href="/privacy_policy/">Privacy Policy</a></li>
<li><a href = "/DMCA/">DMCA</a></li>
</ul>
</li>
<li>
<h4>Scratch Family</h4>
<ul>
<li><a href="http://scratched.gse.harvard.edu/">ScratchEd</a></li>
<li><a href="http://www.scratchjr.org/">ScratchJr</a></li>
<li><a href="http://day.scratch.mit.edu/">Scratch Day</a></li>
<li><a href="/conference/">Scratch Conference</a></li>
<li><a href="http://www.scratchfoundation.org/">Scratch Foundation</a></li>
<li><a href="/store">Scratch Store</a></li>
</ul>
</li>
</ul>
<ul class="clearfix" id="footer-menu" >
<li>
<form id="lang-dropdown" method="post" action="/i18n/setlang/">
<select id="language-selection" name="language">

<option value="ab" >Аҧсшәа</option>

<option value="af" >Afrikaans</option>

<option value="ar" >العربية</option>

<option value="ast" >Asturianu</option>

<option value="am" >አማርኛ</option>

<option value="an" >Aragonés</option>

<option value="az" >Azeri</option>

<option value="id" >Bahasa Indonesia</option>

<option value="bn" >বাংলা</option>

<option value="be" >Беларуская</option>

<option value="bg" >Български</option>

<option value="ca" >Català</option>

<option value="cs" >Česky</option>

<option value="cy" >Cymraeg</option>

<option value="da" >Dansk</option>

<option value="de" >Deutsch</option>

<option value="et" >Eesti</option>

<option value="el" >Ελληνικά</option>

<option value="en" selected >English</option>

<option value="es" >Español (España)</option>

<option value="es-419" >Español Latinoamericano</option>

<option value="eo" >Esperanto</option>

<option value="eu" >Euskara</option>

<option value="fa" >فارسی</option>

<option value="fil" >Filipino</option>

<option value="fr" >Français</option>

<option value="fy" >Frysk</option>

<option value="ga" >Gaeilge</option>

<option value="gd" >Gàidhlig</option>

<option value="gl" >Galego</option>

<option value="ko" >한국어</option>

<option value="ha" >Hausa</option>

<option value="hy" >Հայերեն</option>

<option value="he" >עִבְרִית</option>

<option value="hi" >हिंदी</option>

<option value="hr" >Hrvatski</option>

<option value="xh" >isiXhosa</option>

<option value="zu" >isiZulu</option>

<option value="is" >Íslenska</option>

<option value="it" >Italiano</option>

<option value="ka" >ქართული ენა</option>
<option value="kk" >қазақша</option>

<option value="qu" >Kichwa</option>

<option value="sw" >Kiswahili</option>

<option value="ht" >Kreyòl ayisyen</option>

<option value="ku" >Kurdî</option>

<option value="ckb" >کوردیی ناوەندی</option>

<option value="lv" >Latviešu</option>

<option value="lt" >Lietuvių</option>

<option value="hu" >Magyar</option>

<option value="mi" >Māori</option>

<option value="mn" >Монгол хэл</option>

<option value="nl" >Nederlands</option>

<option value="ja" >日本語</option>

<option value="ja-Hira" >にほんご</option>

<option value="nb" >Norsk Bokmål</option>

<option value="nn" >Norsk Nynorsk</option>

<option value="oc" >Occitan</option>

<option value="or" >ଓଡ଼ିଆ</option>

<option value="uz" >Oʻzbekcha</option>

<option value="th" >ไทย</option>

<option value="km" >ភាសាខ្មែរ</option>

<option value="pl" >Polski</option>

<option value="pt" >Português</option>

<option value="pt-br" >Português Brasileiro</option>

<option value="rap" >Rapa Nui</option>

<option value="ro" >Română</option>

<option value="ru" >Русский</option>

<option value="nso" >Sepedi</option>

<option value="tn" >Setswana</option>

<option value="sk" >Slovenčina</option>

<option value="sl" >Slovenščina</option>
<option value="sr" >Српски</option>

<option value="fi" >Suomi</option>

<option value="sv" >Svenska</option>

<option value="vi" >Tiếng Việt</option>

<option value="tr" >Türkçe</option>

<option value="uk" >Українська</option>

<option value="zh-cn" >简体中文</option>
<option value="zh-tw" >繁體中文</option>
</select>
</form>
</li>
</ul>
</div>
</div>



<!-- templates/modal-login.html block -->
<div class="modal hide fade in" id="login-dialog" style="width: 450px">
<form method="post" action="/login/">
<fieldset>
<div class="modal-header">
<a href="#" data-dismiss="modal" class="close">x
</a>
<h3>Sign in</h3>
</div>
<div class="modal-body">

<div class="control-group">
<label class="control-label" for="username">Username
</label>
<div class="controls">
<input class="username" type="text" name="username" maxlength="30" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password
</label>
<div class="controls">
<input type="password" name="password" class="password" />
</div>
</div>

</div>
<div class="modal-footer">
<span class="error">
</span>
<div class="buttons-right">
<button class="button primary" type="submit">Sign in</button>

<a data-control="registration">Or Join Scratch</a>

</div>
</div>

</fieldset>
</form>
<iframe class="iframeshim" frameborder="0" scrolling="no"><html><head></head><body></body></html></iframe>
</div>
<!-- end templates/modal-login.html -->


<div id="registration" class="registration modal hide fade" data-backdrop="static">
<iframe class="iframeshim" frameborder="0" scrolling="no"><html><head></head><body></body></html></iframe>
</div>








<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__//js/jquery-ui.min.js"></script>

<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/js/main.js" charset="utf-8"></script>
<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/js/base.js" charset="utf-8"></script>
<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/js/lazyload.js" charset="utf-8"></script>







<script type="text/template" id="template-collection-count">
<%- count %>
</script>

<script type="text/template" id="template-comment-actions">
<% if (can_delete) { %>
<% if (is_staff && comment_user == current_user) { %>
<span data-control="delete" class="actions report">Delete</span>
<% } else if (type != "gallery" || comment_user == current_user) { %>
<span data-control="delete" class="actions report">Delete</span>
<% } %>
<% } %>
<% if (current_user != comment_user) { %>
<span data-control="report" class="actions report">
<% if (student_of_educator) { %>
Delete
<% } else { %>
Report
<% } %></span>
<% } %>
</script>

<script type="text/template" id="template-modal-login">
<div class="modal hide fade in" id="login-dialog" style="width: 450px">
<form method="post" action="/login/">
<fieldset>
<div class="modal-header">
<a href="#" data-dismiss="modal" class="close">x </a>
<h3>Login</h3>
</div>
<div class="modal-body">
<div class="control-group">
<label class="control-label" for="username">Username
</label>
<div class="controls">
<input id="username" type="text" name="username" maxlength="30" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password
</label>
<div class="controls">
<input type="password" name="password" id="password" />
</div>
</div>
</div>
<div class="modal-footer">
<span class="error">
</span>
<span class="button primary" id="sign-in" data-control="site-login">
<span>{% trans "Sign in" $}
</span>
</span>
</div>
</fieldset>
</form>
</div>
</script>

<script type="text/template" id="template-comment-reply">
<form>
<div class="control-group tooltip right">
<textarea name="content"></textarea>



<span class="hovertext error" data-control="error" data-content="comment-error"><span class="arrow"></span><span class="text"></span></span>
<span class="small-text">You have <span id="chars-left-<%- comment_id %>">500</span> characters left.</span>
</div>
<div class="control-group">
<div class="button small" data-parent-thread="<%- thread_id %>" data-commentee-id="<%- commentee_id %>" data-control="post"><a href="#null">Post</a></div>
<div class="button small grey" data-control="cancel"><a href="#null">Cancel</a></div>
<span class="notification"></span>
</div>
</form>
</script>

<script type="text/template" id="template-deletion-canceled">
<div class="deletion-canceled">
<div class="form">
<p>
Your account was scheduled for deletion but you logged in. Your account has been reactivated. If you didn’t request for your account to be deleted, you should <a href="/accounts/password_change/">change your password</a> to make sure your account is secure.
</p>
</div>
</div>
</script>

<script type="text/template" id="template-unsupported-browser">
<div class="unsupported-browser banner" data-cue="unsupported_browser">
<div class="container">
<span>Scratch works best on newer browsers. We suggest you upgrade to <a href="/info/faq/#requirements">a supported browser</a>, <a href="/scratch2download/">download the offline editor</a>, <a href="https://en.scratch-wiki.info/wiki/List_of_Bug_Workarounds">or read about common workarounds</a>.</span>
<div class="close">x</div>
</div>
</div>
</script>

<script type="text/template" id="template-unsupported-msie">
<div class="unsupported-browser banner" data-cue="unsupported_browser">
<div class="container">
<span>Scratch will stop supporting Internet Explorer 8 on April 30, 2015. We suggest you upgrade to <a href="/info/faq/#requirements">a supported browser</a>, <a href="/scratch2download/">download the offline editor</a>, or <a href="https://en.scratch-wiki.info/wiki/List_of_Bug_Workarounds">read about common workarounds</a>.</span>
<div class="close">x</div>
</div>
</div>
</script>








<!-- load javascript translation catalog, and javascript fuzzy date library -->
<script type="text/javascript" src="/jsi18n/"></script>
<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__/js/lib/jquery.timeago.settings.js"></script>


<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__//js/apps/registration/main.js"></script>


<script type="text/javascript" src="//cdn.scratch.mit.edu/scratchr2/static/__ff0fb5277364ee597af859e40a9b568a__//js/apps/global.js"></script>
<script>
Scratch.NotificationPollTime = 300000;
</script>




<script>
$(document).on("accountnavready", function(e){
$('#topnav .messages').notificationsAlert();
});
</script>

<script type="text/javascript">
var today = new Date();
if (today.getDate() === 1 && today.getMonth() === 3) {
document.write(';');
}
</script>
</body>
<!-- Site Version: 3.2023.09.29.1_2023_09_29_11_57 --></html>

Last edited by PhilHub (Oct. 24, 2023 06:49:14)

davidtheplatform
Scratcher
500+ posts

Studio "accept invite" API request?

Please put long things in [code] tags
god286
Scratcher
1000+ posts

Studio "accept invite" API request?

You probably need to fix the CSRF token, not sure
PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

davidtheplatform wrote:

Please put long things in [code] tags
Done!
god286
Scratcher
1000+ posts

Studio "accept invite" API request?

If you look at the long text, you will see that it is a 404.
PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

god286 wrote:

You probably need to fix the CSRF token, not sure
I so far, I used TimMcCool's scratch attach source code as a guide, and it didn't return any traceback errors, which was a thing, but it didn't do the thing I wanted, only returned a lengthy html code of the website.

I used this WORKING script as a guide to make my one:
def invite_curator(self, curator):
"""
You can only use this function if this object was created using :meth:`scratchattach.session.Session.connect_studio`
"""
try:
return requests.put(
f"https://scratch.mit.edu/site-api/users/curators-in/{self.id}/invite_curator/?usernames={curator}",
headers = headers,
cookies = self._cookies,
).json()
except Exception:
raise(_exceptions.Unauthorized)

Last edited by PhilHub (Oct. 24, 2023 07:13:52)

god286
Scratcher
1000+ posts

Studio "accept invite" API request?

I just created an implementation for this in meowclient, a package I made which is similar in purpose to scratchclient/scratchattach but in NodeJS. Here is the code, you may be able to convert this to Python.
await fetch(
`https://scratch.mit.edu/site-api/users/curators-in/${this.id}/add/?usernames=${this.session.sessionJSON.user.username}`, {
method: "PUT",
headers: {
"User-Agent": UserAgent,
"X-CSRFToken": this.session.csrfToken,
Cookie: this.session.cookieSet,
Origin: "https://scratch.mit.edu",
Referer: `https://scratch.mit.edu/studios/${this.id}/curators`
}
}
);
(Ignore the fact there is no syntax highlighting - the forum hasn't been updated in years so it doesn't understand how to highlight my code unfortunately)

Last edited by god286 (Oct. 24, 2023 07:36:09)

Sid72020123
Scratcher
500+ posts

Studio "accept invite" API request?

You can use this code here: https://github.com/Sid72020123/scratchconnect/blob/main/scratchconnect/Studio.py#L327

I haven't tested it since many months but it should work…

EDIT: Notice that I used “session.put” with some predefined headers and along-with that, I also added a “referer” header.

This is how the header should look:
headers = {
"x-csrftoken": self.csrf_token,
"X-Token": self.token,
"x-requested-with": "XMLHttpRequest",
"Cookie": f"scratchcsrftoken={self.csrf_token};scratchlanguage=en;scratchsessionsid={self.session_id};",
"referer": "https://scratch.mit.edu",
}

Just replace the referer with the studio's URL

Last edited by Sid72020123 (Oct. 24, 2023 09:22:13)

PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

Sid72020123 wrote:

You can use this code here: https://github.com/Sid72020123/scratchconnect/blob/main/scratchconnect/Studio.py#L327

I haven't tested it since many months but it should work…

EDIT: Notice that I used “session.put” with some predefined headers and along-with that, I also added a “referer” header.

This is how the header should look:
headers = {
"x-csrftoken": self.csrf_token,
"X-Token": self.token,
"x-requested-with": "XMLHttpRequest",
"Cookie": f"scratchcsrftoken={self.csrf_token};scratchlanguage=en;scratchsessionsid={self.session_id};",
"referer": "https://scratch.mit.edu",
}

Just replace the referer with the studio's URL
Thank you! It works now
PhilHub
Scratcher
69 posts

Studio "accept invite" API request?

Guys, this topic is resolved. How do you close it now? By the way here's the working code which I managed to make with the help of LoidesMio, ProgramORDie, and Sid72020123 (note this code uses the scratchattach module to simplify things)

print("importing...")

import scratchattach as scratch3
import time
import os
import requests

def accept_invitation(studio, user):
session._get_csrftoken()
token = session._headers["x-csrftoken"]
headers = {
'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36',
"x-csrftoken": token,
"x-requested-with": "XMLHttpRequest",
"referer": "https://scratch.mit.edu/studios/{studio}/curators/",
}
cookies = {
"scratchsessionsid" : session.session_id,
"scratchcsrftoken" : token,
"scratchlanguage" : "en",
"accept": "application/json",
"Content-Type": "application/json",
}
response = requests.put(f"https://scratch.mit.edu/site-api/users/curators-in/{studio}/add/?usernames={user}", headers=headers, cookies=cookies)
try:
return response.json()
except:
return response.status_code

print("logging in...")

session = scratch3.login("username", "password")

print("making request...")

print(accept_invitation(studio_id, "username_goes_here")
davidtheplatform
Scratcher
500+ posts

Studio "accept invite" API request?

PhilHub wrote:

Guys, this topic is resolved. How do you close it now?
Report the top post and put “resolved” in the reason box

Powered by DjangoBB