Al Grant
Al Grant

Reputation: 2354

Mocking a request to API

I need to mock a request to a API, and I am going to have to do it in excel with Data -> Get Data from web. Tools like postman and fiddler are not available.

So far I have logged in with a browser (SSO) to get a auth token, and I can see requests to the server to get the data, but taking this information and generating a mock request so far has failed. The requests to the API that I inspect in browser look like:

REQUEST HEADERS

 :authority: svmyapp.contoso.com
 :method: POST
 :path: /cms/bridge/sched/rest/editor?token=abcd-defg-hijk-lmnoprqu
 :scheme: https
 cookie: MYAPSSO=ABCDEF....HIJKLMO; CMS_ANALYTCIS=ABCEDF....HIJK; WFS_USER=ABCDEF....HIJKL
 origin: https://myapp.contoso.com
 referer: https://myapp.contoso.com/index.html?ver=9.2.3&domain=&InstanceId=9ec...abc
 csrf_token: ABCD-DEFGH-JKLM

QUERY STRING PARAMS

token: abcd-defg-hijkl-mnop

REQUEST PAYLOAD

A JSON payload with various parameters

The excel get data from web looks like:

enter image description here

But I do not see where to enter the payload?

What are the leading ":" on some of the keys like :method: and is it possible to say which fields at minimum are required to make a request. There are so many tokens involved its hard to know what each does.

Upvotes: 0

Views: 262

Answers (1)

TobyPython
TobyPython

Reputation: 85

That data from web input tool in excel is very limited. You would be better making the request in VBA where you can set multiple headers

 Dim xml_obj As MSXML2.XMLHTTP60
 Set xml_obj = New MSXML2.XMLHTTP60
 base_url = "https:..."
 xml_obj.Open "GET", base_url
    xml_obj.SetRequestHeader "token", "qsdlqwdjlqj"
'repeat above line for each header 
    xml_obj.Send
'Print the status code in case something went wrong
If xml_obj.Status <> 200 Then Debug.Print "The Request was " + CStr(xml_obj.Status)
ResponseA = xml_obj.responseText
Debug.Print ResponseA ' To see what you get back - it will only show first 256 characters but more maybe included in reponse

Also you need to enable by checking the boxes in the VBA Developer -Tools menu - Microsoft XML v 6.0, Microsoft scripting runtime, Microsoft office 16.0 Object Library (or similar versions)

Upvotes: 1

Related Questions