Manipulating file using Shopify graphql admin api - shopify-api

I want to delete a file using deleteFile method from Shopify sandbox. However deleteFile method is requiring file id and the File object doesn't contain id property.
So my question is how do I get file id in shopify graphql ?

You need to get Media Image id but an Image id.
So, you can request this type of id using ... on MediaImage
query files($count: Int, $cursor: String) {
files(first: $count, after: $cursor, sortKey: CREATED_AT, reverse: true) {
edges {
cursor
node {
... on MediaImage {
id
image {
height
width
url
}
}
__typename
}
}
}
}

Related

Fetch the name of Linked Entry in Contentful API

I'm using Contentful API to get the details of all the entries in a Space, is there a way to fetch the name of 'linked entry/entries' to a particular entry? In this case, i'm fetching all the entries with the content_type = HorizontalImageCard and then that each entry has link to other entries(could be a link to an Asset or link to different Contentul entry), and i would like to get the name of such entries, attaching the screenshot of what i'm looking for, in the screenshot there's a Linked Entry called 'Jennifer Test', how do i fetch that name?
let fetchRes = fetch("https://preview.contentful.com/spaces/{space_id}/environments/ca/entries/{entry_id}?access_token=vOKxCDyhU8gLUsU4FR5tgdwQVe3arwfJzFTCloi2sjM&content_type=HorizontalImageCard");
Did you try with the GraphQL API? I didn't get a chance to try it out with the REST API, but I was able to get the result with the GraphQL API. Here's an example query:
{
userCollection(preview:true) {
items {
name
linkedFrom {
blogArticleCollection {
items {
title
}
}
}
}
}
}
The User content type is linked in the Blog Article content type. This method allows me to list all those references. Hope this helps :)

Create custom API with strapi

I've a content type called continent. Which we the name suggests contains all the information about each continents. Strapi already created API endpoints for me like
continents/:id
But I want to search the continent by it's name since the general user won't be able to search by id
I've created the endpoint
continents/:continent_name
I've also created custom controller following documentation
const { sanitizeEntity } =
requiree('strapi-utils');
module.exports = {
async findOne(ctx) {
const { continent_name } = ctx.params;
const entity = await
strapi.services.continent.findOne({
continent_name
});
return sanitizeEntity(entity, { model:
continents });
And also exposed the API to public
But doesn't seem to anything
Just returns error
How am I supposed to do it
For your use case, you don't need to extend the model controller. You can just pass the continent name as a query param . For example, your url could be something like base_url/continent?continent_name=Asia.
For the code mentioned in the question, there is an issue, the model name should be strapi.models.continent and not continents. Also in the first line requiree('strapi-utils'), you have an extra e in the require. I am assuming that was just a typo.

Deployed web part is showing errors in console but not for non-local workbench

I have deployed a web part to a site collection (where the web part is designed to go) and I am getting errors for 3 particular features on the form.
I am using sp.web for these features.
I have created a 'Hello User' which uses this function:
public _getUser() {
sp.web.currentUser.get().then((user) => {
this.setState({
CurrentUserTitle: user.Title,
FullName: user.Title,
CurrentUser: user.LoginName,
CurrentUserID: user.Id,
CurrentUserEmail: user.Email,
}
A Departments list drop down which populates with an SP list.
public _getDepartments() {
sp.web.lists.getByTitle("Departments").items.get().then((items: any[]) => {
let returnedDepts: IDropdownOption[] = items.map((item) => { return { key: item.Title, text: item.Title }; });
this.setState({ DepartmentsList: returnedDepts });
});
}
A Submit button. The function:
private _onSubmit() {
sp.web.lists.getByTitle('Data and Report Form').items.add({
FullName: this.state.FullName,
UniId: this.state.UniId,
Email: this.state.UserEmail,
Phone: this.state.PhoneNo,
Department: this.state.SelectedDept,
SubDepartment: this.state.SubDepartment,
StartDate: this.state.StartDate,
DiscoveryDate: this.state.DateOfDiscovery,
Details: this.state.IncidentDetails,
PersonalData: this.state.PersonalData
}).then((iar: ItemAddResult) => {
console.log(iar);
let list = sp.web.lists.getByTitle('Data and Report Form');
list.items.getById(iar.data.Id).update({
Title: 'DIBR'+iar.data.Id,
});
this.setState({
JobRef: iar.data.Id,
});
});
}
The form works perfectly in non-local SharePoint workbench served on the actual site it's meant to be deployed on.
When deployed as a package to the site itself and added as a web part it now shows these errors:
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(Fetch)GET - https://myDomain.sharepoint.com/sites/IncidentReporting/SitePages/_api/web/currentuser
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(Fetch)GET - https://myDomain.sharepoint.com/sites/IncidentReporting/SitePages/_api/web/lists/getByTitle('Departments')/items
I get a similar message when trying to submit. A I said, these all work on the non-local workbench.
Additional details:
If I add the webpart to the homepage of the modern site as a web part I get these error (different to the ones if I add the webpart to a page):
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(Fetch)GET - https://MyDomain.sharepoint.com/sites/_api/web/lists/getByTitle('Departments')/items
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(Fetch)GET - https://MyDomain.sharepoint.com/sites/_api/web/currentuser
as you can see it's missing the actual site in the URL. Why the difference?
Has anyone got an idea why it's behaving differently when deployed? And why is it showing a different error if I place the web part on different areas of the site collection.
Update: I've attempted to use this:
import pnp from "sp-pnp-js";
public onInit(): Promise<void> {
return super.onInit().then(_ => {
pnp.setup({
spfxContext: this.context
});
});
}
But I don't know how to implement it as onInit is Angular isn't it?
HELP!
T
Figured it out.....
MAKE SURE TO PUT:
https://github.com/SharePoint/PnP-JS-Core/wiki/Using-sp-pnp-js-in-SharePoint-Framework
import pnp from "sp-pnp-js";
// ...
public onInit(): Promise {
return super.onInit().then(_ => {
pnp.setup({
spfxContext: this.context
});
});
In your root .ts file!!!!!
This had me for days!
This issue occurs because the PnP JS API didn’t get the SharePoint context. It is taking the SITEURL + '/SitePages' to get the context.
So, what you need to do is that in the props file, add a new 'siteUrl' property.
export interface IDemoWebPartProps{
description: string;
siteUrl: string;
}
and then in the Webpart.ts file, initialize this property with this value.
public render(): void {
const element: React.ReactElement<IDemoWebPartProps> = React.createElement(
Demo,
{
description: this.properties.description,
siteUrl: this.context.pageContext.web.absoluteUrl
}
);
Finally, In the .tsx file initialize the Web parameter using this property.
let web = new Web(this.props.siteUrl);
and use this to get the data from required lists using pnp-js.

Docusign REST API: Downloading document to string

I am building an app using the docusign API and PHP. I have most of this working except I cannot figure out how to download the document. I have been searching on this site and on the Docusign site. Docusign has an example here, that shows how to get a list of docs in PHP, but the downloading does not have a PHP example. In the Docusign REST API docs they explain the method here. But this says the response is "PDF File".
In my sample code below, I have tried to put the contents into a file, but it creates and empty file. If I print_r($data), I get this:
SplFileObject Object
(
[pathName:SplFileInfo:private] => /tmp/419ULk
[fileName:SplFileInfo:private] => 419ULk
[openMode:SplFileObject:private] => w
[delimiter:SplFileObject:private] => ,
[enclosure:SplFileObject:private] => "
)
It does create the file in /tmp, but I want to keep the document in a string so I send or save to DB.
Here is my controller function:
public function get_document($envelopeId, $cert = FALSE)
{
$save_dir = BASEPATH."../documents/";
if ($envelopeId) {
$this->load->model('docusign_model');
$data = $this->docusign_model->get_document($envelopeId, $cert);
}
file_put_contents($save_dir.$envelopeId.".pdf", $data);
//print_r($data);
die("116");
}
This is in docusign_model:
public function get_document($envelopeId, $cert)
{
$docuSignAuth = $this->auth();
if ($docuSignAuth) {
$envelopeApi = new EnvelopesApi($docuSignAuth->apiClient);
$options = new GetDocumentOptions();
if($cert) {
$options->setCertificate(TRUE);
} else {
$options->setCertificate(FALSE);
}
return $envelopeApi->getDocument($docuSignAuth->accountId, 1, $envelopeId, $options);
}
return false;
}
How can I get this document and keep it in a string?
Any and all help is greatly appreciated!
The content comes back as a file, you have to read the temp file and save that to the desired file
Quick snippet using file_get_contents and file_put_contents
$docStream = $envelopeApi->getDocument($accountId, 1, $envelopeId);
file_put_contents("my_document.pdf", file_get_contents($docStream->getPathname()));
More info DocuSign REST API :: EnvelopeDocuments: get under Get a Single Document as a PDF File

Get GitHub avatar from email or name

I'm trying to get the GitHub user picture (avatar) from users of GitHub.
I've found these API:
https://avatars.githubusercontent.com/<username>
https://avatars.githubusercontent.com/u/<userid>
But I can't find a way to get the avatar from the user email or the user display name.
I can't find documentation about that.
Is there some similar URL API to get what I'm looking for?
You can append .png to the URL for the User's profile to get redirected to their avatar. You can add the query param size to specify a size smaller than the default of 460px wide (i.e. it won't allow larger than 460).
Examples:
https://github.com/twbs.png
https://github.com/npm.png?size=200
https://github.com/github.png?size=40
https://developer.github.com/v3/users/#get-a-single-user
Use the /users/:user endpoint. Should be under avatar_url in the returned json.
For example, my avatar_url can be found by hitting this url.
Edit
There is another way I can think of that is kind of roundabout. Since GitHub uses Gravatar, if you know the email associated with the account, do an md5 hash of the lowercase, stripped email address and construct a url like http://www.gravatar.com/avatar/[md5_here].
This is an old post but nobody has proposed Github Search Users API with scope field :
using in:email : https://api.github.com/search/users?q=bmartel+in%3Aemail
using in:username : https://api.github.com/search/users?q=Bertrand+Martel+in%3Ausername
Or using new Graphql API v4 :
{
search(type: USER, query: "in:email bmartel", first: 1) {
userCount
edges {
node {
... on User {
avatarUrl
}
}
}
}
}
Using GraphQL API v4, this will work too
Query (for username)-
{
user(login: "username") {
avatarUrl
}
}
Response -
{
"data": {
"user": {
"avatarUrl": "https://avatars1.githubusercontent.com/u/..."
}
}
}
GitHub avatar can be accessed through https://avatars.githubusercontent.com/u/YOUR_USER_ID
Optionally, you can modify the size at the end like so https://avatars.githubusercontent.com/u/YOUR_USER_ID?s=460

Resources