How to make a Azure POST API call from PlayCanvas?

Hi,
I am new to PlayCanvas, i just started the week back this development, i want to make a azure GET and POST request from here,
Can anyone please help me how to do this ?

This is my postman token which is working fine when i do the postman call, how can i do it from here?

var request = new RestRequest(Method.GET);
request.AddHeader("postman-token", "132f43ea-d251-b99b-b2a0-762486974faa");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("accept", "application/json;odata=fullmetadata");
request.AddHeader("x-ms-date", "Tue, 30 Aug 2013 18:10:24 GMT");
IRestResponse response = client.Execute(request);

Hi @Sivamurugan and welcome,

PlayCanvas is running regular JavaScript, so you can use any kind of Rest library, vanilla JS methods or even use the PlayCanvas Http class.

To start with add a PlayCanvas script to your project, study the user manual here on how to get started with that:

From there you can add regular Javascript to do your Rest call. For example you can use the native JS fetch object, more on this here:

Or use the PlayCanvas http Class:

Or add a third party library to your project.

1 Like

Hi,
i tried the below code but didnt get a json response throwing an error. what i am doing wrong here?

pc.http.get("azureapiLink",
   
            function (err, response) { 
    "Content-Type:application/json"
    console.log(response.json());
});

Hi @Sivamurugan ,

I think your request isn’t structured correctly. Maybe try like this:

pc.http.del("here type your full url", { 
   "headers": {
      "Content-Type": "application/json"
   }
}, function (err, response) {
    console.log(response);
});
1 Like

i tried the code which you shared getting this error:

It looks like it is working correctly then. The request is reaching the server.
As to why the server rejects your request, you want to look into Azure API documentation.

3 Likes