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

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

Related

How to create new resource from a file via CKAN API with cURL?

The following cURL is from: https://tech.datopian.com/ckan/play-around.html#create-organizations-datasets-and-resources
and lets you add a resource to a datset from a url.
curl -X POST http://ckan:5000/api/3/action/resource_create -H "Authorization: 9c04a69d-79f4-4b4b-b4e1-f2ac31ed961c" -d '{
"package_id": "my-first-dataset",
"url": "https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/100kb.csv",
"description": "This is the best resource ever!" ,
"name": "brand-new-resource"
}'
Was wondering how you could add a resource from a file.
I can share my example request from a Postman collection (hope it helps):
curl --location --request POST 'http://local-ckan/api/3/action/resource_create' \
--header 'Authorization: xxx-yyy-zzz' \
--form 'package_id="dataset-name"' \
--form 'upload=#"/home/tomek/Downloads/example.csv"' \
--form 'name="new-resource-with-file"'
And here's a note on creating resources from my achives while I was dealing with uploading files to CKAN:
API calls are either POST with a JSON body or POST with a multipart/form body. When using multipart/form you can't nest anything (e.g. resources) in the same call so you have to make multiple calls (package_create, resource_create, resource_create, ...). When using JSON you can't upload files as part of the same call so you need to attach any files with separate multipart/form calls e.g. with resource_patch

Can't load some ontologies from URL via GraphDB API

I can load the MonDO ontology into GraphDB Free 9 with the /rest/data/import/upload/{repositoryID}/url method with this body:
{
"context": "http://purl.obolibrary.org/obo/mondo.owl",
"data": "https://github.com/monarch-initiative/mondo/releases/download/current/mondo.owl",
"format": "RDF/XML"
}
I can also load this via the Workbench, but not programatically:
http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
I set the format line to "Turtle" and I'm getting 202 responses, but the workbench doesn't show any import. It seems like some of the time I see error messages on the workbench's import page, but I don't understand what corrective action to take.
For example, if I intentionally import ICD9 via the workbench, with the wrong format (RDF/XML), then I see
RDF Parse Error: Content is not allowed in prolog. [line 2, column 1]
curl 'http://localhost:7200/rest/data/import/upload/w2/url' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"type":"url","name":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","format":"text/turtle","data":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","status":"NONE","message":"","context":"","replaceGraphs":[],"baseURI":null,"forceSerial":false,"timestamp":1534939094325,"parserSettings":{"preserveBNodeIds":false,"failOnUnknownDataTypes":false,"verifyDataTypeValues":false,"normalizeDataTypeValues":false,"failOnUnknownLanguageTags":false,"verifyLanguageTags":true,"normalizeLanguageTags":false,"verifyURISyntax":true,"verifyRelativeURIs":true,"stopOnError":true}}
GraphDB handles api key but you should provide file format in the way up or "format":"text/turtle". Hope this helps.
Thanks to Sava from Ontotext, I was able to construct this minimal curl command that successfully loads the ICD9CM Turtle file from the NCBO BioPortal.
curl -d \
'{"type":"url","format":"text/turtle","data":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","context":"http://data.bioontology.org/ontologies/ICD9CM/"}' \
-H 'Content-Type: application/json;charset=UTF-8' \
-X POST http://localhost:7200/rest/data/import/upload/disease_diagnosis_dev/url
I left out many of the keys, including the timestamp and all of the parserSettings.
I used the - d ... -X POST curl style instead of the --data-binary style
I don't claim to know all of the consequences of those decisions.
Here's my approach in R
library(httr)
post.endpoint <- "http://localhost:7200//rest/data/import/upload/disease_diagnosis_dev/url"
update.body <- '{
"type":"url",
"format":"text/turtle",
"context": "http://purl.bioontology.org/ontology/ICD9CM/",
"data": "http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=9cf735c3-a44a-404f-8b2f-c49d48b2b8b2"
}'
post.result <- POST(post.endpoint,
body = update.body,
content_type("application/json"))
curl 'http://localhost:7200/rest/data/import/upload/abc/url' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"type":"url","name":"http://www.w3.org/TR/owl-guide/wine.rdf","format":"","data":"http://www.w3.org/TR/owl-guide/wine.rdf","status":"NONE","message":"","context":"","replaceGraphs":[],"baseURI":null,"forceSerial":false,"timestamp":1534939094325,"parserSettings":{"preserveBNodeIds":false,"failOnUnknownDataTypes":false,"verifyDataTypeValues":false,"normalizeDataTypeValues":false,"failOnUnknownLanguageTags":false,"verifyLanguageTags":true,"normalizeLanguageTags":false,"verifyURISyntax":true,"verifyRelativeURIs":true,"stopOnError":true}}'
where,
abc - is the repository id
http://www.w3.org/TR/owl-guide/wine.rdf - is the URL to import
1534939094325 - the current timestamp in seconds since epoch (in bash, equivalent to date +%s)
If you want to perform regular updates I advise you to put each file in its own graph (using the "context":"<file's url>") and then replace it with "replaceGraphs":"<file's url>". The database will create a delta and update only the changed statements.

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

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.

How do I perform PUT operation via Gitlab's API?

I want to construct a curl command using Gitlab's API so that I can edit a README.md file. I know it is possible according to docs:
https://docs.gitlab.com/ee/api/repository_files.html
I am able to find my project with curl 'https://private.private.io/api/v4/56/projects?private_token=private-token'but I can't seem to go any deeper in order to read or edit a file in repo.
UPDATE
The solution is
curl --request PUT --header 'PRIVATE-TOKEN: private-token' --header "Content-Type: application/json" --data '{"branch": "master", "author_email": "email", "author_name": "name",
"content": "status, building", "commit_message": "update file"}' 'https://private.private.io/api/v4/projects/56/repository/files/README.md'
Please consider using this solution mentioned in the docs here.THis allows you to update a single file
curl --request PUT --header 'PRIVATE-TOKEN: <your_access_token>' --header "Content-Type: application/json" \
--data '{"branch": "master", "author_email": "author#example.com", "author_name": "Firstname Lastname", \
"content": "some content", "commit_message": "update file"}' \
'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb'

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