I want to upload excel file with form data including unique ID which is generated from previous request - file-upload

Below is payload of the request and below parameter I have extracted from previous request and pass as expected and I have added file upfeId":"3EIBAA2","fileYear":2025,"accountId":"RMhn9AAD","subAccountId":"RcEIzAAN"
I have tried to with different configuration auth token and all variable from previous request have been passed successfully but it is showing bad request can any please help to build this request
operations:
{"operationName":"uploadFile","variables":{"Template":{"fileName":"puneet19Dec2022.xlsx","File":[null],"upfeId":"3EIBAA2","fileYear":2025,"accountId":"RMhn9AAD","subAccountId":"RcEIzAAN"}},"query":"mutation uploadFile($Template: TemplateInput) {\n uploadFile(Template: $Template) {\n responseCode\n responseMessage\n data {\n list {\n name\n notes\n type\n startDate\n dueDate\n owners {\n emailId\n firstName\n __typename\n }\n attachmentName\n phase\n rowError\n __typename\n }\n hasError\n majorErrors\n __typename\n }\n __typename\n }\n}"}
map:
{"1":["variables.fileTemplate.File.0"]}
1:
(binary)

If you can upload your file successfully using browser (or other application) - just record the request using JMeter's HTTP(S) Test Script Recorder. Just make sure to copy the file you will be uploading to "bin" folder of your JMeter installation, this way JMeter will be able to properly intercept the request and generate relevant HTTP Request sampler and HTTP Header Manager
All the dynamic parameters could be correlated later on.
If you were just given the request payload it might be a better idea to use GraphQL HTTP Request which is easier to configure, parameterize and use.

Related

Insert rows in an empty data extension on salesforce marketing cloud by using API call

I didn't achieve to receive data in my data extension (empty) by using the API multiple data extension rows method.
I created a data extension with 7 variables (6 data type = text, 1 is a date). One of the 7 variables is a primary key (text data type).
On postman, I created a first POST request:
URL: https://mc08wx0hkc21mnr8g402m7q36hy4.auth.marketingcloudapis.com/v2/token
In the body:
{
"client_id": " ",
"client_secret": " ",
"account_id": " ",
"grant_type": " "
}
With all the information about the package that I created on marketing cloud and that I have to use:
(scope : data extension => read, write)
By sending this request, I got my access_token.
The second part is more confused for me, I have to make the connection so as to populate my data extension.
I created a second POST request:
In the body:
Host : https://MY_SUBDOMAIN.rest.marketingcloudapis.com
POST /hub/v1/dataevents/key: ID DataExtension/rowset
Content-Type: application/json
Authorization: Bearer eyJhY2Nlc...
The part with the URL is more confused for me. As I said before, I have one primary key in the data extension that I created to receive the datas
URL: https://mc08wx0hkc21mnr8g402m7q36hy4.rest.marketingcloudapis.com/ POST /hub/v1/dataevents/key: EXTERNAL_KEY_OF_MY_DATA_EXTENSION/keys :MY_PRIMARY_KEY_NAME/
I followed the Salesforce docs.
By sending the request, I had:
<h1>596 Service Not Found</h1>

Mulesoft_ passing client id and Client_secret under HTTP header

I have a requirement where I need to add both client id and client_secret under HTTP headers(under attribute,headers)
I tried to use the below code and unfortunately, it is not working, so please check and guide us to get the expected code.
Transform message create an attribute and applied the below DataWeave code:
output application/java
---
{
headers: {
client_id: '68eee04d10774836b6e5c40189ed3efb',
client_secret: '149541B02E23487EBE517708496a2920'
}
And in the consume connector header part, I have added the below line code.
Attributes.headers
It is difficult to say without seeing exactly what the application is doing but I suspect you are mixing SOAP headers with HTTP headers. HTTP Headers go into the transport headers element.
Example assuming both kind of headers in different variables. Note that you can set each header individually or pass an object which contains them all:
<wsc:consume doc:name="Consume" config-ref="Web_Service_Consumer_Config" operation="GetContent">
<wsc:message>
<wsc:headers><![CDATA[#[vars.soapHeaders]]]></wsc:headers>
</wsc:message>
<wsc:transport-headers>
<wsc:transport-header key="client_id" value="#[vars.httpHeaders.client_id]" />
<wsc:transport-header key="client_secret" value="#[vars.httpHeaders.client_secret]" />
</wsc:transport-headers>
</wsc:consume>

How to solve HTTPError: 400 Client Error: Bad Request for URL inRobot Frame work

I know there are many similar kinds of questions available but none of them worked.
Can someone tell me if there is any kind of syntax error for the Testcase below
Create Token
Create Session testsession ${baseUrl} verify=true
${body}= create dictionary clientId=unittest.cc.client clientSecret=RyDQ$xxxxxRtv
${header}= create dictionary Content-Type=application/json
${resp}= POST On Session testsession ${reqUri} json=${body} headers=${header} params=${ApiKeyParameter}
${source data}= Evaluate json.loads("""${resp.content}""") json
${token}= Set Variable ${source data['accessToken']}
#No errors Uptill this much - Bearer token creation was successful after that getting error while using it
${header}= create dictionary Authorization=${tpre} ${token} Content-Type=application/json cookies=ss-id=KF84fFy4txxxxxxxxx76i; ss-pid=StDTDxxxxxxxxxxxxn7r
${body}= get file API/data.txt
log to console ${header}
${resp}= post on session testsession /orders json=${body} headers=${header}
log to console ${resp.status_code}
The problem is every time I run the test I am getting a 400 error. Below is the Python code provided by POSTMAN and the screenshots of the headers used. Now I am not sure of how to get the HOST header in my python or maybe robot framework.
Please let me know if any additional details are needed. I am not sure of headers in the URL formation while get or post request is done
Is there any way to find that out?
import requests
import JSON
url = "https://domain:10001/orders?format=json"
payload = json.dumps({ Can ignore this part
})
headers = {
'Authorization': 'Bearer xxx',
'Content-Type': 'application/json',
'Cookie': 'ss-id=xxx; ss-pid=xxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
If you all ever come across this kind of issue don't forget to check the body of the JSON / XML you are sending.
Mine resolved as I was saving the dump JSON in a text file so while reading from the file my code was adding some extra spaces in front so I was getting a 400 error.
For further information try logging the Response Content it must show you the error message.

How to set dynamic variable in postman

I am working on set of API development which needs authorization so in headers I have to include key as Authorization and value as Bearer <access_token> like below:
I have another authorization api which I call and in return it gives me below data which has token value:
{
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJub25jZSI6IkNwMTFCNXRGaWZLOZ1lOQXp5ZnZUa1hWMXhkbXJHOXBtem1xY0NRQT0iLCJhcHBfZGlzcGxheW5hbWUiOiJ1c2VyYWNjZXNzIiwiYXBwaWQiOiIyNDg4YTNiNi00MjlhLTQyZWMtYTVhZi04ZTQzZWFjNjJlMWIiLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC80ZjdjNzBhNy1mOGRlLTRhMzMtOGYzNS05OWE5ZDQ1NThkODUvIiwiaWR0eXAiOiJhcHAiLCJvaWQiOiJmNDk2NjUwZS1kOTgzLTRjNDItODViNC03NzYxZjljMTEzZDQiLCJyaCI6IjAuQVhjQXAzQjhUOTc0TTBxUE5ab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SobrBWuFel7gmdmstAWPeNLj5hIM2mQueNuyOa3PucR9qfOr0yQ-FA7I4F2UjFLN7WfU0NhP0hnI3Qg4mnnq1xc727kvZWC9KzbEszVpEnVtewLxKgWIIwRl_NsG6ghIO0utc3aJsU8f7oULVtb99gUhLM-4v5YcAk2xZebRoVnsJYv4tfg8cZJasG9POv7akzdjD8tKhjF1hOGjcowY3E0AxdiC4wYU0S7fj2Mpx4HD1gV9hPneFTgaA",
"expires_in": "3599",
"expires_on": "1618296096",
"ext_expires_in": "3599",
"not_before": "1618292196",
"resource": "https://graph.microsoft.com",
"token_type": "Bearer"
},
"msg": "",
"status": true
}
It has access_token which I have to copy in all the other apis to authorize. This token expires every 60min so I have to copy paste the token again and again. Is there any way available through which I can define a dynamic variable in postman and assign it value of access_token so that whenever it expires, I simply query the authorization api and value of that dynamic variable is automatically refreshed. This will help in copy pasting the token again in all the other APIs.
EDIT:
I have set the token variable in getoauthtoken api
In another api, I have now used {{token}} but looks like its not able to find it
You should be able to use this in the Tests tab:
pm.globals.set('token', pm.response.json.data.access_token)
Once you have the variable saved, you can use {{token}} as the header value.
If it expires, make the token request again to set the new value everywhere.
Alternatively, you could use something like this (you would need to modify the script for your context) to automatically refresh the token when it expires:
https://dannydainton.com/2018/09/10/postman-the-bearer-of-good-news/
You can go the the Test tab. and copy/paste this code javascript code.
pm.environment.set('token', pm.response.json().token)
And after the saving the token value into the environment variable you can go to the Authorization tab and click on the Type dropdown menu and select Bearer token like in screenshoot.
And then place this into the token input {{token}}

Getting response as 'Unauthorized' while sending access token via URI Query Parameter

We are creating REST API and implemented oAuth 2, using YII framework.
We are facing a strange issue, while we are trying to access the resource and sending access token via "Authorization Request Header Field" we are getting the expected output.
e.g.
curl -i -H "Accept:application/json" -H "Authorization: Bearer XXXXXX"
Whereas while we are trying to send the access token via "URI Query Parameter" we are getting response as "Unauthorized".
e.g.
https://server.example.com/resource?access_token=XXXXXX&p=q
Your suggestions would be really helpful for us.
RFC 6750 (Bearer Token Usage) defines 3 ways to pass an access token to a protected resource endpoint.
Via Authorization header. (2.1. Authorization Request Header Field)
Via a form parameter access_token. (2.2. Form-Encoded Body Parameter)
Via a query parameter access_token. (2.3. URI Query Parameter)
Among the above, only the first way is mandatory. It seems your authorization server does not support the third way.
Addition for the comment
Below is an example to support all the 3 ways in PHP. See "3. Extract Access Token" in "Protected Resource" for details and for other examples in Ruby and Java.
/**
* Function to extract an access token from a request.
*/
function extract_access_token()
{
// The value of Authorization header.
$header = $_SERVER['HTTP_AUTHORIZATION'];
// If the value is in the format of 'Bearer access-token'.
if ($header != null && preg_match('/^Bearer[ ]+(.+)/i', $header, $captured))
{
// Return the value extracted from Authorization header.
return $captured;
}
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
// Return the value of 'access_token' query parameter.
return $_GET['access_token'];
}
else
{
// Return the value of 'access_token' form parameter.
return $_POST['access_token'];
}
}
I don't know Yii, but my guess is that simply the framework does not contain code like the above.