Getting "You don't have a required scope to access the endpoint" when inserting script - bigcommerce

I'm developing an app, for store fronts and want to get some analytics in checkout. So I want to inject a script in that scope of checkout. When I try to insert it I'm getting "You don't have a required scope to access the endpoint" but I have updated the scopes to checkoutcontent to modify. Not sure what else is wrong
Trying to insert script via an app, getting 403 even though I updated the OAuth scopes to include, Check out content and Checkout
curl --request POST \
--url https://api.bigcommerce.com/stores/{store_hash}/v3/content/scripts \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-auth-client: XXXXX' \
--header 'x-auth-token: XXXXX' \
--data '{"name":"Test Scripts Tag","description":"Test Scripts Tag","html":"<script src=\\\"https://Somedestination/Test.js\\\"></script>","src":"https://Somedestination/Test.js","auto_uninstall":true,"load_method":"default","location":"footer","visibility":"checkout","kind":"src"}'
Getting below error, while expecting a status=200
status: 403,You don't have a required scope to access the endpoint

The html field shouldn't be included when using src, could you try removing it?
The only errors I was receiving in testing were due to malformed HTML in the html field with the error code 422. It may also be worth trying to create a new API account to rule out scoping causing this.

Related

How can I create new TeamCity users through the API?

I want to create TeamCity users with various roles through the API. As long as I provide no role, I know how to do it, like so:
curl -X POST http://localhost:8111/app/rest/users \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"password"}' \
-u :<super-user-token>
Now, my issue is that e.g. I want to create an administrator. I tried this:
curl -X POST http://localhost:8111/app/rest/users \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"password", "roles": {"role": [{"roleId": "PROJECT_ADMIN"}]}}' \
-u :<super-user-token>
The roleId is a value that comes from the roles-config.xml file in folder <TeamCity Data Directory>/config, should be fine. I get the following error:
Responding with error, status code: 400 (Bad Request).
Details: jetbrains.buildServer.server.rest.errors.PartialUpdateError: Partial error updating user 'zadigus' {id=3}, nested errors: jetbrains.buildServer.server.rest.errors.PartialUpdat
eError: Partial error updating roles for user 'zadigus' {id=3}, nested errors: java.lang.IllegalArgumentException: Argument for #NotNull parameter 'scopeData' of jetbrains/buildServer/
server/rest/model/user/RoleAssignment.getScope must not be null
There was an error processing the request, but the data could be updated partially. Please ensure consistent data state.
because I provide no scope. I was not able to find any information about what values I can feed the scope field with. Where are they documented?
I am using TeamCity version 2022.04.4.
I found it. In order to get the possible values for the scope field, just run
curl -X POST http://localhost:8111/app/rest/users \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"password", "roles": {"role": [{"roleId": "PROJECT_ADMIN", "scope": "invalid-value"}]}}' \
-u :<super-user-token>
In the reply to this request, we get the information that possible values are either g or p:<projectId>.

Not able to create ENV variable using API token

I was trying to automate creating ENV variables in CI/CD by using API commands, but unfortunately getting 401 Unauthorized error.
Earlier I used to do this in same way and was able to do it.
But now it’s throwing an error, could anyone please help me to find out.
Command:
curl --request POST --header “PRIVATE-TOKEN: <your_access_token>” \
“https://gitlab.com/api/v4/projects/1/variables” --form “key=NEW_VARIABLE” --form “value=new value”
Please look into the error message:
The "Create a variable" API call indeed looks like:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value"
(make sure to use the right double-quotes " instead of “)
Double-check the ID of the project (in your case "1") and make sure the user authenticated with your token has the right permissions:
They must be "maintainer" or "owner", in order to have the right to "Manage project-level CI/CD variables".
Example, using a Personal Access Token with api scope, starting with glpat- (glpat-xxxxxxx), I can first list my projects (using jq):
curl -XGET --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/owned?=true"|jq ".[] | \"\(.id) \(.path_with_namespace)\""
That allows me to find the project id
I can then list variables for an existing project:
curl -XGET --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/<projectId>/variables"
Result:
[]
I have none on that project.
I will set one with:
curl -XPOST --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/<projectId>/variables" --form "key=NEW_VARIABLE" --form "value=new value"
Result:
{"variable_type":"env_var","key":"NEW_VARIABLE","value":"new value","protected":false,"masked":false,"environment_scope":"*"}
Let's double-check with:
curl -XGET --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/<projectId>/variables"
Result:
[{"variable_type":"env_var","key":"NEW_VARIABLE","value":"new value","protected":false,"masked":false,"environment_scope":"*"}]
It does work.
The OP Anirban Das confirms in the comments an issue with how Postman was used:
Actually in the body of Postman, select 'form', there I had mentioned directly key name in the Key section and value in the Value section.
But that was not correct.
In the Key section, we need to mention "key" and key name should be in Value section.
Similarly "value" in key section and it's value in Value section.
Once this worked, you will see "</>" icon in right navigation pane, which will provide you corresponding curl command

dremio list user API

I'm trying to query dremio using the documented API to get list of users.
Dremio version:
Build
20.2.2-202203241726030461-f7eea3e0
Edition
Enterprise Edition
API:
https://docs.dremio.com/software/rest-api/user/list-users/
sample query:
curl -X GET --location "http://localhost:9047/api/v3/user" \
-H "Authorization: _dremiohrr395nv31g8k610616tucp91g" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
I keep getting this error:
{
"errorMessage": "Something went wrong. Please check the log file for details, see https://docs.dremio.com/advanced-administration/log-files.html",
"moreInfo": "HTTP 405 Method Not Allowed"
}
It seems that this API is not supported at all.
Is there a published API to list all users so that I can get user name, uid, and role memberships?
I'm trying to avoid using SQL query.
v3 list users API is buggy.
user apiv2/user works

How do I use the REST API to update an Apex Trigger?

curl --location --request PUT 'https://ap17.salesforce.com/services/data/v48.0/sobjects/ApexTrigger/01q2x000000YiNcAAK' \
--header 'Authorization: Bearer 00D2....' \
--header 'Content-Type: application/json' \
--data-raw '{
"Name": "ContactCreateUpdateDeleteApexTrigger",
"TableEnumOrId": "Contact",
"Body":"trigger ContactCreateUpdateDeleteApexTrigger on Contact (after update,after insert, after delete) { String url = '\''https:endpoint.com'\''; String content = WebhookClass.jsonContent(Trigger.new, Trigger.old,'\''Contact'\''); WebhookClass.callout(url, content); }"
}'
I am getting 200 Response but my triggers are not updated.
Apex class, Apex trigger tables are visible just for reference purposes and backups. What you do is not a simple data manipulation operation, it has to be a proper deployment with compilation, running unit tests, min 75% code coverage... Especially that your endpoint looks like a production.
Check the Tooling API, it's also RESTful. This should be a nice start: https://salesforce.stackexchange.com/q/156221

How to change --header 'Accept: application/json' to --header 'Accept: application/xml'

WSO2 API manger how to change --header 'Accept: application/json' to --header 'Accept: application/xml'?
I have added some APIs to WSO2 API Publisher. I can connect via API Console for some API but some failed. I noticed the one failing due to --header Accept: application/json'- all other which connected successfully has --header 'Accept: application/xml.
Also it keep return Response Code 0 with Response Headers:
"error": "no response from server"
I have tried to update this but still the same: /opt/wso2am-2.1.0/repository/deployment/server/synapse-configs/default/sequences/_auth_failure_handler_.xml
Please advise.
In the publisher where you define the resources for your API, you can specify the "Produces" field (set it to application/xml), that should be used as the default value from the API Store test console.
Regardless that - the client could post any Accept header in the request. The "Produces" field is only an indication, it doesn't enforce the header value.
I suggest you test the calls anyway using the curl (SoapUI, Postman or any other feasible tool) so you can see what the service REALLY returns. The "Response Code 0" message usually means some error response (400, 500, .. anything) it's just not necessarily shown in the DEV console.
Have fun